From 2758b864bc7e314273ee4d4dfb74c2a4cb686541 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 20 Sep 2025 18:04:59 +0100 Subject: [PATCH] fix bug found by unit test: when deleting leftwards, we should never delete beyond the end of the line --- fcore/normal-mode/make-normal-delete.sml | 16 +++++++++++++++- fcore/normal-mode/normal-mode.sml | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/fcore/normal-mode/make-normal-delete.sml b/fcore/normal-mode/make-normal-delete.sml index b4a2e1f..d7104ac 100644 --- a/fcore/normal-mode/make-normal-delete.sml +++ b/fcore/normal-mode/make-normal-delete.sml @@ -213,7 +213,7 @@ struct fun deleteByDfa (app: app_type, count, fMove, time) = let - val {buffer, cursorIdx, searchString, ...} = app + val {buffer, cursorIdx, ...} = app val buffer = LineGap.goToIdx (cursorIdx, buffer) val otherIdx = fMove (buffer, cursorIdx, count) @@ -225,6 +225,20 @@ struct deleteAndFinish (app, low, length, buffer, time) end + fun deleteCharsLeft (app: app_type, count, time) = + let + val {buffer, cursorIdx, ...} = app + + val buffer = LineGap.goToIdx (cursorIdx, buffer) + val startOfLine = Cursor.vi0 (buffer, cursorIdx) + val low = Cursor.viH (buffer, cursorIdx, count) + val low = if low < startOfLine then startOfLine else low + + val length = cursorIdx - low + in + deleteAndFinish (app, low, length, buffer, time) + end + fun deleteToEndOfPrevWord (app: app_type, count, time) = let val {buffer, cursorIdx, searchString, ...} = app diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index 5ef4a25..dd1a4e9 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -250,7 +250,7 @@ struct fun parseDeleteTerminal (str, count, app, chrCmd, time) = case chrCmd of (* terminal commands: require no input after *) - #"h" => NormalDelete.deleteByDfa (app, count, Cursor.viH, time) + #"h" => NormalDelete.deleteCharsLeft (app, count, time) | #"l" => NormalDelete.deleteByDfa (app, count, Cursor.viL, time) (* vi's 'j' and 'k' commands move up or down a column * but 'dj' or 'dk' delete whole lines