done reimplementing 'MakeNormalDelete.deleteLineBack', taking care of cases where we use this motion while on the first line or on the last
This commit is contained in:
@@ -60,7 +60,13 @@ struct
|
|||||||
(* figure out where to place cursor *)
|
(* figure out where to place cursor *)
|
||||||
val buffer = LineGap.goToIdx (lineStart, buffer)
|
val buffer = LineGap.goToIdx (lineStart, buffer)
|
||||||
val lineEndAfterDelete = Cursor.viDlr (buffer, lineStart, 1)
|
val lineEndAfterDelete = Cursor.viDlr (buffer, lineStart, 1)
|
||||||
|
|
||||||
val cursorIdx = Int.min (lineEndAfterDelete, cursorIdx)
|
val cursorIdx = Int.min (lineEndAfterDelete, cursorIdx)
|
||||||
|
val cursorIdx =
|
||||||
|
if cursorIdx >= #textLength buffer - 2 then
|
||||||
|
Int.max (0, #textLength buffer - 2)
|
||||||
|
else
|
||||||
|
cursorIdx
|
||||||
in
|
in
|
||||||
finishAfterDeletingBuffer (app, cursorIdx, buffer, time, initialMsg)
|
finishAfterDeletingBuffer (app, cursorIdx, buffer, time, initialMsg)
|
||||||
end
|
end
|
||||||
@@ -340,6 +346,32 @@ struct
|
|||||||
finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg)
|
finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun finishDeleteLineBack (app, buffer, lineIdx, length, endOfLine, time) =
|
||||||
|
if endOfLine >= #textLength buffer - 2 then
|
||||||
|
(* deleting from last line *)
|
||||||
|
let
|
||||||
|
(* go to first column of previous line *)
|
||||||
|
val buffer = LineGap.goToIdx (lineIdx, buffer)
|
||||||
|
val newCursorIdx = Cursor.viH (buffer, lineIdx, 1)
|
||||||
|
val buffer = LineGap.goToIdx (newCursorIdx, buffer)
|
||||||
|
val newCursorIdx = Cursor.vi0 (buffer, newCursorIdx)
|
||||||
|
|
||||||
|
(* clip endOfLine so we leave a newline at end of file *)
|
||||||
|
val endOfLine = Int.max (0, #textLength buffer - 1)
|
||||||
|
|
||||||
|
val buffer = LineGap.goToIdx (endOfLine, buffer)
|
||||||
|
val initialMsg = Fn.initMsgs (lineIdx, length, buffer)
|
||||||
|
val buffer = LineGap.delete (lineIdx, length, buffer)
|
||||||
|
|
||||||
|
val buffer =
|
||||||
|
if #textLength buffer = 0 then LineGap.append ("\n", buffer)
|
||||||
|
else buffer
|
||||||
|
in
|
||||||
|
finishAfterDeletingBuffer (app, newCursorIdx, buffer, time, initialMsg)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
deleteAndFinish (app, lineIdx, length, buffer, time)
|
||||||
|
|
||||||
fun deleteLineBack (app: app_type, count, time) =
|
fun deleteLineBack (app: app_type, count, time) =
|
||||||
let
|
let
|
||||||
val {buffer, cursorIdx, ...} = app
|
val {buffer, cursorIdx, ...} = app
|
||||||
@@ -355,34 +387,19 @@ struct
|
|||||||
if cursorLineNumber = 0 then
|
if cursorLineNumber = 0 then
|
||||||
NormalFinish.clearMode app
|
NormalFinish.clearMode app
|
||||||
else if newCursorLineNumber = 0 then
|
else if newCursorLineNumber = 0 then
|
||||||
let
|
(* deleting from current line to start of file *)
|
||||||
val endOfLine = Cursor.viDlr (buffer, cursorIdx, 1) + 2
|
let val endOfLine = Cursor.viDlr (buffer, cursorIdx, 1) + 2
|
||||||
val buffer = LineGap.goToIdx (endOfLine, buffer)
|
in finishDeleteLineBack (app, buffer, 0, endOfLine, endOfLine, time)
|
||||||
val endOfLine =
|
|
||||||
if endOfLine >= #textLength buffer - 2 then
|
|
||||||
Int.max (0, #textLength buffer - 2)
|
|
||||||
else
|
|
||||||
endOfLine
|
|
||||||
in
|
|
||||||
deleteAndFinish (app, 1, endOfLine, buffer, time)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val endOfLine = Cursor.viDlr (buffer, cursorIdx, 1) + 1
|
val endOfLine = Cursor.viDlr (buffer, cursorIdx, 1) + 1
|
||||||
val endOfLine =
|
|
||||||
if endOfLine >= #textLength buffer - 2 then
|
|
||||||
Int.max (0, #textLength buffer - 2)
|
|
||||||
else
|
|
||||||
endOfLine
|
|
||||||
|
|
||||||
val buffer = LineGap.goToLine (newCursorLineNumber, buffer)
|
val buffer = LineGap.goToLine (newCursorLineNumber, buffer)
|
||||||
|
|
||||||
val lineIdx = LineGap.lineNumberToIdx (newCursorLineNumber, buffer)
|
val lineIdx = LineGap.lineNumberToIdx (newCursorLineNumber, buffer)
|
||||||
val buffer = LineGap.goToIdx (lineIdx, buffer)
|
|
||||||
|
|
||||||
val length = endOfLine - lineIdx
|
val length = endOfLine - lineIdx
|
||||||
in
|
in
|
||||||
deleteAndFinish (app, lineIdx, length, buffer, time)
|
finishDeleteLineBack (app, buffer, lineIdx, length, endOfLine, time)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user