reimplement d% motion so that it first searches for the next occurrence of a pair-character before trying to match it. (Next: add tests for d% motion.)
This commit is contained in:
@@ -1132,36 +1132,45 @@ struct
|
|||||||
fun deletePair (app: app_type, time) =
|
fun deletePair (app: app_type, time) =
|
||||||
let
|
let
|
||||||
val {cursorIdx, buffer, dfa, ...} = app
|
val {cursorIdx, buffer, dfa, ...} = app
|
||||||
val otherIdx = Cursor.matchPair (buffer, cursorIdx)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
val otherIdx = Cursor.nextPairChr (buffer, cursorIdx)
|
||||||
in
|
in
|
||||||
if otherIdx = cursorIdx then
|
if otherIdx = ~1 then
|
||||||
NormalFinish.clearMode app
|
NormalFinish.clearMode app
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val low = Int.min (cursorIdx, otherIdx)
|
val buffer = LineGap.goToIdx (otherIdx, buffer)
|
||||||
val high = Int.max (cursorIdx, otherIdx)
|
val otherIdx = Cursor.matchPair (buffer, otherIdx)
|
||||||
val length = high - low + 1
|
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (high, buffer)
|
|
||||||
val initialMsg = Fn.initMsgs (low, length, buffer)
|
|
||||||
|
|
||||||
val buffer = LineGap.delete (low, length, buffer)
|
|
||||||
val (buffer, searchList) = SearchList.build (buffer, dfa)
|
|
||||||
|
|
||||||
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 buffer = LineGap.goToIdx (low, buffer)
|
|
||||||
in
|
in
|
||||||
NormalFinish.buildTextAndClear
|
if otherIdx = ~1 then
|
||||||
(app, buffer, low, searchList, initialMsg, time)
|
NormalFinish.clearMode app
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val low = Int.min (cursorIdx, otherIdx)
|
||||||
|
val high = Int.max (cursorIdx, otherIdx)
|
||||||
|
val length = high - low + 1
|
||||||
|
|
||||||
|
val buffer = LineGap.goToIdx (high, buffer)
|
||||||
|
val initialMsg = Fn.initMsgs (low, length, buffer)
|
||||||
|
|
||||||
|
val buffer = LineGap.delete (low, length, buffer)
|
||||||
|
val (buffer, searchList) = SearchList.build (buffer, dfa)
|
||||||
|
|
||||||
|
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 buffer = LineGap.goToIdx (low, buffer)
|
||||||
|
in
|
||||||
|
NormalFinish.buildTextAndClear
|
||||||
|
(app, buffer, low, searchList, initialMsg, time)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
4
todo.md
4
todo.md
@@ -1,9 +1,7 @@
|
|||||||
# To-do list
|
# To-do list
|
||||||
|
|
||||||
- Add tests for:
|
- Add tests for:
|
||||||
- Reimplement `d%` motion.
|
- `d%` motion
|
||||||
- It should both search for the next character in any pair, the same way in Vim
|
|
||||||
- Add tests for reimplemented movements and motions
|
|
||||||
- Reimplement `di<symbol>` and `da<symbol>`
|
- Reimplement `di<symbol>` and `da<symbol>`
|
||||||
- They should search for the next char in the specific pair, the same way in Vim
|
- They should search for the next char in the specific pair, the same way in Vim
|
||||||
- Add tests for both
|
- Add tests for both
|
||||||
|
|||||||
Reference in New Issue
Block a user