From 8c23db23d2d9bd5247e62d126fa104d8fbceffdb Mon Sep 17 00:00:00 2001 From: Kai Saba Date: Wed, 11 Dec 2024 15:59:32 +0100 Subject: [PATCH] fix: fix locked code ranges and text split --- src/tools/utils/editorOperationUtils.ts | 5 +++-- src/tools/utils/rangeUtils.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tools/utils/editorOperationUtils.ts b/src/tools/utils/editorOperationUtils.ts index ba40642..16ed79f 100644 --- a/src/tools/utils/editorOperationUtils.ts +++ b/src/tools/utils/editorOperationUtils.ts @@ -60,7 +60,8 @@ function splitOperationText ( if (rangeText != null && rangeText !== '') { const rangeTextIndex = textToSplit.indexOf(rangeText) if (rangeTextIndex !== -1) { - splitText.push(textToSplit.slice(0, rangeTextIndex)) + const endIndex = textToSplit.endsWith('\n') ? rangeTextIndex - 1 : rangeTextIndex + splitText.push(textToSplit.slice(0, endIndex)) textToSplit = textToSplit.slice(rangeTextIndex + rangeText.length) } else { splitText.push(textToSplit) @@ -71,7 +72,7 @@ function splitOperationText ( } if (textToSplit !== '') { - splitText.push(textToSplit) + splitText.push(textToSplit.endsWith('\n') ? textToSplit.slice(0, textToSplit.length - 1) : textToSplit) } return splitText } diff --git a/src/tools/utils/rangeUtils.ts b/src/tools/utils/rangeUtils.ts index 85de807..70fc462 100644 --- a/src/tools/utils/rangeUtils.ts +++ b/src/tools/utils/rangeUtils.ts @@ -52,7 +52,7 @@ export function minusRanges ( } if (lastEndPosition.isBeforeOrEqual(uniqueRangeEndPosition)) { - firstRanges.push(monaco.Range.fromPositions(lastEndPosition, uniqueRangeEndPosition)) + firstRanges.push(monaco.Range.fromPositions(model.modifyPosition(lastEndPosition, 1), uniqueRangeEndPosition)) } return { firstRanges, secondRanges }