diff --git a/fcore/normal-mode/normal-delete.sml b/fcore/normal-mode/normal-delete.sml index 778679c..fa6326d 100644 --- a/fcore/normal-mode/normal-delete.sml +++ b/fcore/normal-mode/normal-delete.sml @@ -5,9 +5,9 @@ struct fun deleteAndFinish (app: app_type, low, length, buffer) = let - val searchString = #searchString app val buffer = LineGap.delete (low, length, buffer) + val searchString = #searchString app val buffer = LineGap.goToEnd buffer val initialMsg = [SEARCH (buffer, searchString)] @@ -479,4 +479,42 @@ struct if low = high then Finish.clearMode app else deleteAndFinish (app, low, high - low + 1, buffer) end + + fun deletePair (app: app_type) = + let + val {cursorIdx, buffer, ...} = app + val otherIdx = Cursor.matchPair (buffer, cursorIdx) + in + if otherIdx = cursorIdx then + Finish.clearMode app + else + let + val low = Int.min (cursorIdx, otherIdx) + val high = Int.max (cursorIdx, otherIdx) + val length = high - low + 1 + + val buffer = LineGap.delete (low, length, buffer) + val buffer = LineGap.goToIdx (low, buffer) + + val low = + if Cursor.isCursorAtStartOfLine (buffer, low) then + (* we may have deleted the last character of this current line, + * and if we did, we have to move the cursor back by 1 *) + Int.max (low - 1, 0) + else + low + + val searchString = #searchString app + val buffer = LineGap.goToEnd buffer + val initialMsg = [SEARCH (buffer, searchString)] + + val buffer = LineGap.goToIdx (low + 777, buffer) + val searchList = + SearchList.buildRange (buffer, searchString, low - 777) + + val buffer = LineGap.goToIdx (low, buffer) + in + Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg) + end + end end diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index 47b2120..fda050a 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -166,6 +166,7 @@ struct | #"d" => NormalDelete.deleteLine (app, count) | #"n" => NormalDelete.deleteToNextMatch (app, count) | #"N" => NormalDelete.deleteToPrevMatch (app, count) + | #"%" => NormalDelete.deletePair app (* non-terminal commands which require appending chr *) | #"t" => appendChr (app, chr, str) | #"T" => appendChr (app, chr, str)