Skip to content

Commit

Permalink
fix: fix locked code ranges and text split
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSaba committed Dec 11, 2024
1 parent 0c5ae90 commit cf76aee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/tools/utils/editorOperationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,18 @@ function splitOperationText (
if (rangeText != null && rangeText !== '') {
const rangeTextIndex = textToSplit.indexOf(rangeText)
if (rangeTextIndex !== -1) {
splitText.push(textToSplit.slice(0, rangeTextIndex))
const currentUneditableRange = uneditableRanges[currentRange]!
let textToKeep = textToSplit.slice(0, rangeTextIndex)
if (textToKeep.endsWith('\n') && currentUneditableRange.startColumn === 1) {
textToKeep = textToKeep.slice(0, textToKeep.length - 1)
}
splitText.push(textToKeep)

const uneditableRangeMaxEndColumn = model.getLineMaxColumn(currentUneditableRange.endLineNumber)
textToSplit = textToSplit.slice(rangeTextIndex + rangeText.length)
if (textToSplit.startsWith('\n') && currentUneditableRange.endColumn === uneditableRangeMaxEndColumn) {
textToSplit = textToSplit.slice(1, textToSplit.length)
}
} else {
splitText.push(textToSplit)
textToSplit = ''
Expand All @@ -71,7 +81,7 @@ function splitOperationText (
}

if (textToSplit !== '') {
splitText.push(textToSplit)
splitText.push(textToSplit.endsWith('\n') ? textToSplit.slice(0, textToSplit.length - 1) : textToSplit)
}
return splitText
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/utils/rangeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit cf76aee

Please sign in to comment.