implement 'dG' motion (need to test it next)

This commit is contained in:
2025-10-16 01:13:14 +01:00
parent 5fcee88911
commit a855cecd25
3 changed files with 32 additions and 5 deletions

View File

@@ -727,10 +727,7 @@ struct
val buffer = LineGap.delete (0, cursorIdx, buffer)
val buffer =
if #textLength buffer = 0 then
LineGap.fromString "\n"
else
buffer
if #textLength buffer = 0 then LineGap.fromString "\n" else buffer
val buffer = LineGap.goToStart buffer
val initialMsg = SEARCH (buffer, dfa, time) :: initialMsg
@@ -771,6 +768,35 @@ struct
)
end
fun deleteToEnd (app: app_type, time) =
let
val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val startOfLineIdx = Cursor.vi0 (buffer, cursorIdx)
val length = #textLength buffer - startOfLineIdx
val buffer = LineGap.goToIdx (#textLength buffer, buffer)
val initialMsg = Fn.initMsgs (startOfLineIdx, length, buffer)
val buffer = LineGap.delete (startOfLineIdx, length, buffer)
val buffer =
if #textLength buffer = 0 then LineGap.fromString "\n" else buffer
val newLineEndIdx = Int.max (startOfLineIdx - 1, 0)
val buffer = LineGap.goToIdx (newLineEndIdx, buffer)
val newLineEndIdx =
if Cursor.isOnNewlineAfterChr (buffer, newLineEndIdx) then
Int.max (newLineEndIdx - 1, 0)
else
newLineEndIdx
val buffer = LineGap.goToIdx (newLineEndIdx, buffer)
val newLineStartIdx = Cursor.vi0 (buffer, newLineEndIdx)
in
finishAfterDeletingBuffer (app, newLineStartIdx, buffer, time, initialMsg)
end
fun helpDeleteToMatch (app: app_type, low, high, time) =
let
val {buffer, dfa, ...} = app

View File

@@ -274,6 +274,7 @@ struct
| #"n" => NormalDelete.deleteToNextMatch (app, count, time)
| #"N" => NormalDelete.deleteToPrevMatch (app, count, time)
| #"%" => NormalDelete.deletePair (app, time)
| #"G" => NormalDelete.deleteToEnd (app, time)
(* non-terminal commands which require appending chr *)
| #"t" => appendChr (app, chrCmd, str)
| #"T" => appendChr (app, chrCmd, str)

View File

@@ -1,6 +1,7 @@
# To-do list
- Add tests for:
- `dG`
- `d$`
- `d^`
- `dd`
@@ -18,6 +19,5 @@
- Reimplement `di<symbol>` and `da<symbol>`
- They should search for the next char in the specific pair, the same way in Vim
- Add tests for both
- Implement `dG` motion and test it
Afterwards, add tests for yanking.