From 33866533a3c29b8483351642150792185ed0d7f8 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 8 Feb 2026 03:17:19 +0000 Subject: [PATCH] address remainning todo-notes, which had to do with updating the searchList when we insert into a buffer. --- fcore/normal-mode/make-normal-delete.sml | 10 ++++----- fcore/normal-mode/normal-mode.sml | 27 ++++++++---------------- fcore/persistent-vector.sml | 2 +- fcore/search-list/search-list.sml | 11 ++++++---- todo.md | 2 +- 5 files changed, 22 insertions(+), 30 deletions(-) diff --git a/fcore/normal-mode/make-normal-delete.sml b/fcore/normal-mode/make-normal-delete.sml index cc78082..00e3e6a 100644 --- a/fcore/normal-mode/make-normal-delete.sml +++ b/fcore/normal-mode/make-normal-delete.sml @@ -185,11 +185,10 @@ struct (app, cursorIdx, buffer, searchList, time, []) else let - (* todo: have not implemented search-list-rebuilding - * for insertions yet *) val (buffer, searchList) = SearchList.deleteBufferAndSearchList (newCursorIdx, 1, buffer, searchList, dfa) - val buffer = LineGap.insert (newCursorIdx, " ", buffer) + val (buffer, searchList) = SearchList.insert + (newCursorIdx, " ", buffer, searchList, dfa) in helpRemoveLineBreaks (app, buffer, newCursorIdx, count - 1, time, searchList, dfa) @@ -233,11 +232,10 @@ struct NormalFinish.clearMode app else let - (* todo: have not implemented search-list-rebuilding - * for insertions yet *) val (buffer, searchList) = SearchList.deleteBufferAndSearchList (newCursorIdx, 1, buffer, searchList, dfa) - val buffer = LineGap.insert (newCursorIdx, " ", buffer) + val (buffer, searchList) = SearchList.insert + (newCursorIdx, " ", buffer, searchList, dfa) in helpRemoveLineBreaks (app, buffer, newCursorIdx, count - 1, time, searchList, dfa) diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index e7a921e..befd4f1 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -26,28 +26,17 @@ struct end local - fun loop (app: app_type, cursorIdx, buffer, count, time) = + fun loop (app: app_type, cursorIdx, buffer, searchList, count, time) = if count = 0 then - let - open MailboxType - - val {cursorIdx = origCursorIdx, dfa, ...} = app - val buffer = LineGap.goToStart buffer - - (* todo: try updating searchList incrementally - * instead of rebuilding from scratch *) - val (buffer, searchList) = SearchList.build (buffer, dfa) - in - NormalDelete.finishAfterDeletingBuffer - (app, origCursorIdx, buffer, searchList, time, []) - end + NormalDelete.finishAfterDeletingBuffer + (app, #cursorIdx app, buffer, searchList, time, []) else let val buffer = LineGap.goToIdx (cursorIdx, buffer) val lineStart = Cursor.vi0 (buffer, cursorIdx) - (* todo: update searchList based on insert *) - val buffer = LineGap.insert (lineStart, " ", buffer) + val (buffer, searchList) = SearchList.insert + (lineStart, " ", buffer, searchList, #dfa app) val buffer = LineGap.goToIdx (lineStart, buffer) val lineEnd = Cursor.viDlr (buffer, lineStart, 1) @@ -56,11 +45,13 @@ struct val count = if lineEnd = nextLine then 0 else count - 1 in - loop (app, nextLine, buffer, count, time) + loop (app, nextLine, buffer, searchList, count, time) end in fun indnetLine (app: app_type, count, time) = - loop (app, #cursorIdx app, #buffer app, count, time) + let val {buffer, searchList, cursorIdx, ...} = app + in loop (app, cursorIdx, buffer, searchList, count, time) + end end local diff --git a/fcore/persistent-vector.sml b/fcore/persistent-vector.sml index 36bcb65..673727f 100644 --- a/fcore/persistent-vector.sml +++ b/fcore/persistent-vector.sml @@ -552,7 +552,7 @@ struct let val items = Vector.map (fn {start, finish} => - {start = start - incBy, finish = finish - incBy} + {start = start + incBy, finish = finish + incBy} ) items val sizes = Vector.map #finish items in diff --git a/fcore/search-list/search-list.sml b/fcore/search-list/search-list.sml index 6a219f1..9b066f7 100644 --- a/fcore/search-list/search-list.sml +++ b/fcore/search-list/search-list.sml @@ -226,14 +226,17 @@ struct val searchList = let val searchListLeft = PersistentVector.splitLeft (insIdx, searchList) - val searchListRight = PersistentVector.splitRight (insIdx, searchList) + + val insLength = String.size insString val searchListRight = - PersistentVector.incrementBy (String.size insString, searchList) + PersistentVector.splitRight (insIdx + insLength, searchList) + val searchListRight = PersistentVector.empty in - PersistentVector.merge (searchListLeft, searchListRight) + if PersistentVector.isEmpty searchListLeft then searchListRight + else if PersistentVector.isEmpty searchListRight then searchListLeft + else PersistentVector.merge (searchListLeft, searchListRight) end - (* start looking for new matches from the previous match *) val oldStart = PersistentVector.prevMatch (insIdx, searchList, 1) in if Vector.length dfa = 0 then diff --git a/todo.md b/todo.md index 0790529..45fe24b 100644 --- a/todo.md +++ b/todo.md @@ -1,5 +1,5 @@ # To-do list -- Address to-do notes in make-normal-delete.sml (update searchList in light of insertion) +- Add tests for indent, dedent and remove-line-break motions - Add normal-delete tests for each motion, checking that searchList is as expected - Add tests for other yank motoins - Tests should be based on existing tests for delete-motions, and in the same order.