when deleting inside pair, instead of searching either for either chr1 or chr2 and stopping at first match, search instead for openChr and closeChr, and keep an integer tracking what level of nesting we are at. This gives us the behaviour we want, which is to delete the pair at the correct level of nesting. When we encounter openChr, we increment the nesting counter by 1 and continue searching. When we encounter closeChr, if the nesting counter is 0, we return the current index, but if the nesting counter is higher than 0 when encounter closeChr, we decrement the nesting counter by 1 and continue searching.

This commit is contained in:
2026-01-02 18:50:04 +00:00
parent 37b6f6ab0a
commit 886f384490
4 changed files with 99 additions and 18 deletions

View File

@@ -1035,6 +1035,51 @@ struct
deleteAndFinish (app, low, length, buffer, time)
end
fun deleteInsidePair (app: app_type, openChr, closeChr, time) =
let
val {buffer, cursorIdx, dfa, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val nextIdx =
Cursor.toCloseChrNext
(buffer, cursorIdx, {openChr = openChr, closeChr = closeChr})
in
if nextIdx = ~1 then
NormalFinish.clearMode app
else
let
val buffer = LineGap.goToIdx (nextIdx, buffer)
val matchIdx = Cursor.matchPair (buffer, nextIdx)
in
if matchIdx = ~1 then
NormalFinish.clearMode app
else
let
val low = Int.min (nextIdx, matchIdx)
val high = Int.max (nextIdx, matchIdx)
in
if high = low + 1 then
NormalFinish.clearMode app
else
let
val deleteLow = low + 1
val length = high - deleteLow
val buffer = LineGap.goToIdx (high, buffer)
val initialMsg = Fn.initMsgs (deleteLow, length, buffer)
val buffer = LineGap.delete (deleteLow, length, buffer)
val (buffer, searchList) = SearchList.build (buffer, dfa)
val buffer = LineGap.goToIdx (low, buffer)
in
NormalFinish.buildTextAndClear
(app, buffer, low, searchList, initialMsg, time)
end
end
end
end
fun finishAfterDeleteInside (app: app_type, origLow, high, time) =
if origLow = high then
NormalFinish.clearMode app