remove 'Cursor.tillPrevChr', replacing usages of that function with 'Cursor.toPrevChr'

This commit is contained in:
2025-10-19 14:30:26 +01:00
parent 60ec24453f
commit 7d1272180b
5 changed files with 130 additions and 274 deletions

View File

@@ -757,6 +757,39 @@ struct
end
end
fun deleteToPrevChr (app: app_type, count, chr, time) =
let
val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val newCursorIdx =
Cursor.toPrevChr (buffer, cursorIdx, {findChr = chr, count = count})
in
if newCursorIdx = ~1 then
NormalFinish.clearMode app
else
let val length = cursorIdx - newCursorIdx
in deleteAndFinish (app, newCursorIdx, length, buffer, time)
end
end
fun deleteTillPrevChr (app: app_type, count, chr, time) =
let
val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val newCursorIdx =
Cursor.toPrevChr (buffer, cursorIdx, {findChr = chr, count = count})
in
if newCursorIdx = ~1 then
NormalFinish.clearMode app
else
let
val low = newCursorIdx + 1
val length = cursorIdx - newCursorIdx - 1
in
deleteAndFinish (app, low, length, buffer, time)
end
end
fun deleteToStart (app: app_type, time) : AppType.app_type =
let
val {cursorIdx, buffer, windowWidth, windowHeight, dfa, ...} = app
@@ -964,7 +997,7 @@ struct
val start = cursorIdx + 1
val buffer = LineGap.goToIdx (start, buffer)
val origLow = Cursor.toPrevChr (buffer, start, chr)
val origLow = Cursor.toPrevChr (buffer, start, {findChr = chr, count = 1})
val buffer = LineGap.goToIdx (origLow, buffer)
val high = Cursor.matchPair (buffer, origLow)
in
@@ -1007,7 +1040,7 @@ struct
val start = cursorIdx + 1
val buffer = LineGap.goToIdx (start, buffer)
val low = Cursor.toPrevChr (buffer, start, chr)
val low = Cursor.toPrevChr (buffer, start, {findChr = chr, count = 1})
val buffer = LineGap.goToIdx (low, buffer)
val high = Cursor.matchPair (buffer, low)
in

View File

@@ -132,9 +132,6 @@ struct
end
end
fun parseMoveToChr (count, app, fMove, chrCmd) =
NormalMove.moveToChr (app, count, fMove, chrCmd)
fun parseGo (count, app, chrCmd) =
case chrCmd of
#"e" => MoveToEndOfPrevWord.move (app, count)
@@ -299,13 +296,9 @@ struct
(* have to continue parsing string *)
case String.sub (str, strPos + 1) of
#"t" => NormalDelete.deleteTillNextChr (app, count, chrCmd, time)
| #"T" =>
NormalDelete.deleteToChr
(app, 1, Cursor.tillPrevChr, op-, chrCmd, time)
| #"T" => NormalDelete.deleteTillPrevChr (app, count, chrCmd, time)
| #"f" => NormalDelete.deleteToNextChr (app, count, chrCmd, time)
| #"F" =>
NormalDelete.deleteToChr
(app, count, Cursor.toPrevChr, op-, chrCmd, time)
| #"F" => NormalDelete.deleteToPrevChr (app, count, chrCmd, time)
| #"g" => parseDeleteGo (app, count, chrCmd, time)
| #"i" => parseDeleteInside (app, chrCmd, time)
| #"a" => parseDeleteAround (app, chrCmd, time)
@@ -394,13 +387,9 @@ struct
(* have to continue parsing string *)
case String.sub (str, strPos + 1) of
#"t" => NormalYankDelete.deleteTillNextChr (app, count, chrCmd, time)
| #"T" =>
NormalYankDelete.deleteToChr
(app, 1, Cursor.tillPrevChr, op-, chrCmd, time)
| #"T" => NormalYankDelete.deleteTillPrevChr (app, count, chrCmd, time)
| #"f" => NormalYankDelete.deleteToNextChr (app, count, chrCmd, time)
| #"F" =>
NormalYankDelete.deleteToChr
(app, count, Cursor.toPrevChr, op-, chrCmd, time)
| #"F" => NormalYankDelete.deleteToPrevChr (app, count, chrCmd, time)
| #"g" => parseDeleteGo (app, count, chrCmd, time)
| #"i" => parseDeleteInside (app, chrCmd, time)
| #"a" => parseDeleteAround (app, chrCmd, time)
@@ -530,10 +519,9 @@ struct
else
case String.sub (str, strPos + 1) of
#"t" => NormalYank.yankTillNextChr (app, count, chrCmd)
| #"T" => NormalYank.yankToChr (app, 1, Cursor.tillPrevChr, op-, chrCmd)
| #"T" => NormalYank.yankTillPrevChr (app, count, chrCmd)
| #"f" => NormalYank.yankToNextChr (app, count, chrCmd)
| #"F" =>
NormalYank.yankToChr (app, count, Cursor.toPrevChr, op-, chrCmd)
| #"F" => NormalYank.yankToPrevChr (app, count, chrCmd)
| #"g" => parseYankGo (count, app, chrCmd)
| #"i" => parseYankInside (app, chrCmd)
| #"a" => parseYankAround (app, chrCmd)
@@ -553,15 +541,11 @@ struct
* *)
case String.sub (str, strPos) of
#"t" => NormalMove.tillNextChr (app, count, chrCmd)
| #"T" =>
(* to just before chr, backward *)
parseMoveToChr (1, app, Cursor.tillPrevChr, chrCmd)
| #"T" => NormalMove.tillPrevChr (app, count, chrCmd)
| #"y" => ParseYank.parseYank (strPos, str, count, app, chrCmd, time)
| #"d" => ParseDelete.parseDelete (strPos, str, count, app, chrCmd, time)
| #"f" => NormalMove.toNextChr (app, count, chrCmd)
| #"F" =>
(* to chr, backward *)
parseMoveToChr (count, app, Cursor.toPrevChr, chrCmd)
| #"F" => NormalMove.toPrevChr (app, count, chrCmd)
| #"g" => (* go *) parseGo (count, app, chrCmd)
| #"c" => (* change *) NormalFinish.clearMode app
| _ =>

View File

@@ -544,4 +544,32 @@ struct
NormalFinish.buildTextAndClear
(app, buffer, newCursorIdx - 1, searchList, [], bufferModifyTime)
end
fun toPrevChr (app: app_type, count, chr) =
let
val {cursorIdx, buffer, searchList, bufferModifyTime, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val newCursorIdx =
Cursor.toPrevChr (buffer, cursorIdx, {findChr = chr, count = count})
in
if newCursorIdx = ~1 then
NormalFinish.clearMode app
else
NormalFinish.buildTextAndClear
(app, buffer, newCursorIdx, searchList, [], bufferModifyTime)
end
fun tillPrevChr (app: app_type, count, chr) =
let
val {cursorIdx, buffer, searchList, bufferModifyTime, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val newCursorIdx =
Cursor.toPrevChr (buffer, cursorIdx, {findChr = chr, count = count})
in
if newCursorIdx = ~1 then
NormalFinish.clearMode app
else
NormalFinish.buildTextAndClear
(app, buffer, newCursorIdx + 1, searchList, [], bufferModifyTime)
end
end

View File

@@ -272,17 +272,46 @@ struct
end
end
fun yankToChr (app: app_type, count, fMove, fInc, chr) =
helpYankToChr
( app
, #buffer app
, #cursorIdx app
, #cursorIdx app
, count
, fMove
, fInc
, chr
)
fun yankToPrevChr (app: app_type, count, chr) =
let
val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val newCursorIdx =
Cursor.toPrevChr (buffer, cursorIdx, {findChr = chr, count = count})
in
if newCursorIdx = ~1 then
NormalFinish.clearMode app
else
let
val length = cursorIdx - newCursorIdx
val str = LineGap.substring (newCursorIdx, length, buffer)
val msg = YANK str
val mode = NORMAL_MODE ""
in
NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg])
end
end
fun yankTillPrevChr (app: app_type, count, chr) =
let
val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val newCursorIdx =
Cursor.toPrevChr (buffer, cursorIdx, {findChr = chr, count = count})
in
if newCursorIdx = ~1 then
NormalFinish.clearMode app
else
let
val newCursorIdx = newCursorIdx + 1
val length = cursorIdx - newCursorIdx
val str = LineGap.substring (newCursorIdx, length, buffer)
val msg = YANK str
val mode = NORMAL_MODE ""
in
NormalModeWith.modeAndBuffer (app, buffer, mode, [DRAW msg])
end
end
fun yankToStart (app: app_type) =
let
@@ -354,7 +383,7 @@ struct
val start = cursorIdx + 1
val buffer = LineGap.goToIdx (start, buffer)
val low = Cursor.toPrevChr (buffer, start, chr)
val low = Cursor.toPrevChr (buffer, start, {findChr = chr, count = 1})
val buffer = LineGap.goToIdx (low, buffer)
val high = Cursor.matchPair (buffer, low)
val buffer = LineGap.goToIdx (high, buffer)
@@ -386,7 +415,7 @@ struct
val start = cursorIdx + 1
val buffer = LineGap.goToIdx (start, buffer)
val low = Cursor.toPrevChr (buffer, start, chr)
val low = Cursor.toPrevChr (buffer, start, {findChr = chr, count = 1})
val buffer = LineGap.goToIdx (low, buffer)
val high = Cursor.matchPair (buffer, low) + 1
val buffer = LineGap.goToIdx (high, buffer)