fix edge case with 'd$' motion: if deleting to end of file, we need to append two newlines
This commit is contained in:
@@ -272,6 +272,7 @@ struct
|
|||||||
fun deleteToEndOfLine (app: app_type, time) =
|
fun deleteToEndOfLine (app: app_type, time) =
|
||||||
let
|
let
|
||||||
val {buffer, cursorIdx, ...} = app
|
val {buffer, cursorIdx, ...} = app
|
||||||
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
in
|
in
|
||||||
if Cursor.isCursorAtStartOfLine (buffer, cursorIdx) then
|
if Cursor.isCursorAtStartOfLine (buffer, cursorIdx) then
|
||||||
(* if we are on \n, we don't want to delete or do anything
|
(* if we are on \n, we don't want to delete or do anything
|
||||||
@@ -280,9 +281,19 @@ struct
|
|||||||
else
|
else
|
||||||
let
|
let
|
||||||
val lineStart = Cursor.vi0 (buffer, cursorIdx)
|
val lineStart = Cursor.vi0 (buffer, cursorIdx)
|
||||||
val high = Cursor.viDlrForDelete (buffer, cursorIdx, 1) - 1
|
val high = Cursor.viDlrForDelete (buffer, cursorIdx, 1)
|
||||||
val length = high - cursorIdx
|
val length = high - cursorIdx
|
||||||
|
|
||||||
|
(* we might want to delete to the end of the file.
|
||||||
|
* If so, we will append a double-newline.
|
||||||
|
* The second newline is to comply with Unix-style line endings
|
||||||
|
* and the first newline provides a place for our cursor to rest. *)
|
||||||
|
val buffer =
|
||||||
|
if high > #textLength buffer - 1 then
|
||||||
|
LineGap.append ("\n\n", buffer)
|
||||||
|
else
|
||||||
|
buffer
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (high, buffer)
|
val buffer = LineGap.goToIdx (high, buffer)
|
||||||
val initialMsg = Fn.initMsgs (cursorIdx, length, buffer)
|
val initialMsg = Fn.initMsgs (cursorIdx, length, buffer)
|
||||||
val buffer = LineGap.delete (cursorIdx, length, buffer)
|
val buffer = LineGap.delete (cursorIdx, length, buffer)
|
||||||
|
|||||||
Reference in New Issue
Block a user