begin reimplementing 'MakeNormalDelete.deleteLine' function

This commit is contained in:
2025-09-24 17:58:37 +01:00
parent 80078196e0
commit 2076d25653
2 changed files with 56 additions and 24 deletions

View File

@@ -351,34 +351,36 @@ struct
val startIdx = Cursor.vi0 (buffer, cursorIdx) val startIdx = Cursor.vi0 (buffer, cursorIdx)
val buffer = LineGap.goToIdx (startIdx, buffer) val buffer = LineGap.goToIdx (startIdx, buffer)
val finishIdx = Cursor.viDlr (buffer, cursorIdx, count) + 2 val startLine =
val length = finishIdx - startIdx if cursorIdx = startIdx then
LineGap.idxToLineNumber (cursorIdx + 1, buffer)
else
LineGap.idxToLineNumber (cursorIdx + 1, buffer)
val endLine = startLine + count
val textLengthBeforeDelete = #textLength buffer val buffer = LineGap.goToLine (endLine, buffer)
val endLineIdx = LineGap.lineNumberToIdx (endLine, buffer)
val buffer = LineGap.goToIdx (endLineIdx - 1, buffer)
val buffer = LineGap.goToIdx (startIdx, buffer) (* get "real" endLine by not considering newline after non-newline *)
val initialMsg = Fn.initMsgs (startIdx, length, buffer) val endLine =
val buffer = LineGap.delete (startIdx, length, buffer) if Cursor.isOnNewlineAfterChr (buffer, endLineIdx - 1) then
LineGap.idxToLineNumber (endLineIdx - 1, buffer)
else
LineGap.idxToLineNumber (endLineIdx, buffer)
in in
if finishIdx >= textLengthBeforeDelete - 1 then if endLineIdx = #textLength buffer andalso endLine = startLine then
(* we deleted to the end of the buffer. (* cursor is already on last line so not deleting *)
* Let's check if there is a newline at the end NormalModeWith.bufferMsgsAndMode (app, buffer, [], NORMAL_MODE "")
* and insert one if there isn't. *)
let
val lastPosAfterDelete = #textLength buffer - 1
val buffer = LineGap.goToIdx (lastPosAfterDelete, buffer)
val buffer =
if lastPosAfterDelete < 0 then
LineGap.append ("\n", buffer)
else if Cursor.isCursorAtStartOfLine (buffer, lastPosAfterDelete) then
buffer
else
LineGap.append ("\n", buffer)
in
finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg)
end
else else
finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg) let
val () = print "not on last line so have to delete\n"
val () = print
("startLine = " ^ Int.toString startLine ^ "; endLine = "
^ Int.toString endLine ^ "\n")
in
raise Fail ""
end
end end
fun finishDeleteLineBack (app, buffer, lineIdx, length, endOfLine, time) = fun finishDeleteLineBack (app, buffer, lineIdx, length, endOfLine, time) =

View File

@@ -2,6 +2,36 @@ structure NormalModeWith =
struct struct
open AppType open AppType
fun bufferMsgsAndMode (app: app_type, newBuffer, newMsgs, newMode) =
let
val
{ mode = _
, buffer = _
, msgs = _
, bufferModifyTime
, windowWidth
, windowHeight
, searchList
, visualScrollColumn
, searchString
, startLine
, cursorIdx
} = app
in
{ mode = newMode
, buffer = newBuffer
, msgs = newMsgs
, bufferModifyTime = bufferModifyTime
, windowWidth = windowWidth
, windowHeight = windowHeight
, searchList = searchList
, visualScrollColumn = visualScrollColumn
, searchString = searchString
, startLine = startLine
, cursorIdx = cursorIdx
}
end
fun bufferAndSize fun bufferAndSize
( app: app_type ( app: app_type
, newBuffer , newBuffer