a bit of refactoring

This commit is contained in:
2025-09-02 12:39:50 +01:00
parent d135526386
commit d7f69574af
2 changed files with 80 additions and 96 deletions

View File

@@ -256,90 +256,9 @@ struct
| #"E" => | #"E" =>
NormalYank.yankWhenMovingForward (app, Cursor.endOfWORDForDelete, count) NormalYank.yankWhenMovingForward (app, Cursor.endOfWORDForDelete, count)
| #"$" => NormalYank.yankWhenMovingForward (app, Cursor.viDlr, 1) | #"$" => NormalYank.yankWhenMovingForward (app, Cursor.viDlr, 1)
| #"^" => | #"^" => NormalYank.yankToFirstNonSpaceChr app
let | #"G" => NormalYank.yankToEndOfText app
open DrawMsg | #"%" => NormalYank.yankToMatchingPair app
open MailboxType
val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val otherIdx = Cursor.vi0 (buffer, cursorIdx)
val buffer = LineGap.goToIdx (otherIdx, buffer)
val otherIdx = Cursor.firstNonSpaceChr (buffer, otherIdx)
in
if cursorIdx > otherIdx then
(* yanking backwards from cursorIdx *)
let
val () = print "272\n"
val length = cursorIdx - otherIdx + 1
val buffer = LineGap.goToIdx (otherIdx, buffer)
val str = LineGap.substring (otherIdx, length, buffer)
val msg = YANK str
val mode = NORMAL_MODE ""
in
NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg])
end
else if cursorIdx < otherIdx then
(* yanking forward from cursorIdx *)
let
val length = otherIdx - cursorIdx
val str = LineGap.substring (cursorIdx, length, buffer)
val msg = YANK str
val mode = NORMAL_MODE ""
in
NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg])
end
else
NormalFinish.clearMode app
end
| #"G" =>
let
open DrawMsg
open MailboxType
val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToEnd buffer
val {rightStrings, idx, ...} = buffer
val finishIdx = Int.max (0, idx - 1)
val length = finishIdx - cursorIdx
val str = LineGap.substring (cursorIdx, length, buffer)
val msg = YANK str
val mode = NORMAL_MODE ""
in
NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg])
end
| #"%" =>
let
open DrawMsg
open MailboxType
val {buffer, cursorIdx, ...} = app
val otherIdx = Cursor.matchPair (buffer, cursorIdx)
in
if cursorIdx = otherIdx then
NormalFinish.clearMode app
else
let
val low = Int.min (cursorIdx, otherIdx)
val high = Int.max (cursorIdx, otherIdx)
val length = high - low + 1
val buffer = LineGap.goToIdx (high, buffer)
val str = LineGap.substring (low, length, buffer)
val msg = YANK str
val mode = NORMAL_MODE ""
in
NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg])
end
end
| #"n" => | #"n" =>
let let
open DrawMsg open DrawMsg

View File

@@ -6,9 +6,6 @@ struct
fun yankLine (app: app_type, count) = fun yankLine (app: app_type, count) =
let let
open DrawMsg
open MailboxType
val {buffer, cursorIdx, ...} = app val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
@@ -29,9 +26,6 @@ struct
fun yankToStartOfLine (app: app_type) = fun yankToStartOfLine (app: app_type) =
let let
open DrawMsg
open MailboxType
val {buffer, cursorIdx, ...} = app val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
@@ -48,9 +42,6 @@ struct
fun yankWhenMovingBack (app: app_type, fMove, count) = fun yankWhenMovingBack (app: app_type, fMove, count) =
let let
open DrawMsg
open MailboxType
val {buffer, cursorIdx, ...} = app val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
@@ -67,9 +58,6 @@ struct
fun yankWhenMovingForward (app: app_type, fMove, count) = fun yankWhenMovingForward (app: app_type, fMove, count) =
let let
open DrawMsg
open MailboxType
val {buffer, cursorIdx, ...} = app val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
@@ -84,4 +72,81 @@ struct
in in
NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg]) NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg])
end end
fun yankToFirstNonSpaceChr (app: app_type) =
let
val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val otherIdx = Cursor.vi0 (buffer, cursorIdx)
val buffer = LineGap.goToIdx (otherIdx, buffer)
val otherIdx = Cursor.firstNonSpaceChr (buffer, otherIdx)
in
if cursorIdx > otherIdx then
(* yanking backwards from cursorIdx *)
let
val () = print "272\n"
val length = cursorIdx - otherIdx + 1
val buffer = LineGap.goToIdx (otherIdx, buffer)
val str = LineGap.substring (otherIdx, length, buffer)
val msg = YANK str
val mode = NORMAL_MODE ""
in
NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg])
end
else if cursorIdx < otherIdx then
(* yanking forward from cursorIdx *)
let
val length = otherIdx - cursorIdx
val str = LineGap.substring (cursorIdx, length, buffer)
val msg = YANK str
val mode = NORMAL_MODE ""
in
NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg])
end
else
NormalFinish.clearMode app
end
fun yankToEndOfText (app: app_type) =
let
val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToEnd buffer
val {rightStrings, idx, ...} = buffer
val finishIdx = Int.max (0, idx - 1)
val length = finishIdx - cursorIdx
val str = LineGap.substring (cursorIdx, length, buffer)
val msg = YANK str
val mode = NORMAL_MODE ""
in
NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg])
end
fun yankToMatchingPair (app: app_type) =
let
val {buffer, cursorIdx, ...} = app
val otherIdx = Cursor.matchPair (buffer, cursorIdx)
in
if cursorIdx = otherIdx then
NormalFinish.clearMode app
else
let
val low = Int.min (cursorIdx, otherIdx)
val high = Int.max (cursorIdx, otherIdx)
val length = high - low + 1
val buffer = LineGap.goToIdx (high, buffer)
val str = LineGap.substring (low, length, buffer)
val msg = YANK str
val mode = NORMAL_MODE ""
in
NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg])
end
end
end end