Skip to content

Commit

Permalink
fix: use string indexOf instead of split to split text at the first o…
Browse files Browse the repository at this point in the history
…ccurrence only
  • Loading branch information
KaiSaba committed Dec 9, 2024
1 parent 8412173 commit e47df09
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/tools/utils/editorOperationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ function splitOperationText (
const splitText: string[] = []
const uneditableRangesText = uneditableRanges.map(range => model.getValueInRange(range))
let currentRange: number = 0
let textToSplit: string | undefined = text
while (textToSplit != null && textToSplit !== '' && currentRange < uneditableRangesText.length) {
let textToSplit: string = text
while (textToSplit !== '' && currentRange < uneditableRangesText.length) {
const rangeText = uneditableRangesText[currentRange]
if (rangeText != null && rangeText !== '') {
const result: string[] = textToSplit.split(rangeText)
splitText.push(result[0]!)
textToSplit = result[1]
const rangeTextIndex = textToSplit.indexOf(rangeText)
splitText.push(textToSplit.slice(0, rangeTextIndex))
textToSplit = textToSplit.slice(rangeTextIndex + rangeText.length)
}
currentRange++
}

if (textToSplit != null && textToSplit !== '') {
if (textToSplit !== '') {
splitText.push(textToSplit)
}
return splitText
Expand Down

0 comments on commit e47df09

Please sign in to comment.