fix bug found by unit test: when deleting leftwards, we should never delete beyond the end of the line
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user