implmenet 'daW' motion (next: test it)

This commit is contained in:
2025-12-13 03:57:21 +00:00
parent 204f549c79
commit d1b865bda8
3 changed files with 127 additions and 3 deletions

View File

@@ -790,6 +790,130 @@ struct
fun aroundWordNext (lineGap, cursorIdx) =
AroundWordNext.foldNext (lineGap, cursorIdx, ())
structure AroundWORDPrev =
MakeIfCharFolderPrev
(struct
type env = unit
fun loopNonSpace (strPos, shd, absIdx, stl) =
if strPos < 0 then
case stl of
shd :: stl =>
loopNonSpace (String.size shd - 1, shd, absIdx, stl)
| [] => 0
else
let
val chr = String.sub (shd, strPos)
in
if Char.isSpace chr then absIdx + 1
else loopNonSpace (strPos - 1, shd, absIdx - 1, stl)
end
fun loopSpace (strPos, shd, absIdx, stl) =
if strPos < 0 then
case stl of
shd :: stl => loopSpace (String.size shd - 1, shd, absIdx, stl)
| [] => 0
else
let
val chr = String.sub (shd, strPos)
in
if chr = #"\n" then
absIdx + 1
else if Char.isSpace chr then
loopSpace (strPos - 1, shd, absIdx - 1, stl)
else
absIdx + 1
end
fun fStart (strPos, shd, _, absIdx, stl, _, _) =
let
val chr = String.sub (shd, strPos)
in
if chr = #"\n" then
absIdx
else if Char.isSpace chr then
loopSpace (strPos - 1, shd, absIdx - 1, stl)
else
loopNonSpace (strPos - 1, shd, absIdx - 1, stl)
end
end)
fun aroundWORDPrev (lineGap, cursorIdx) =
AroundWORDPrev.foldPrev (lineGap, cursorIdx, ())
structure AroundWORDNext =
MakeIfCharFolderNext
(struct
type env = unit
fun stopAtFirstNonSpace (strPos, shd, absIdx, stl) =
if strPos = String.size shd then
case stl of
shd :: stl => stopAtFirstNonSpace (0, shd, absIdx, stl)
| [] => absIdx
else
let
val chr = String.sub (shd, strPos)
in
if chr = #"\n" then
absIdx - 1
else if Char.isSpace chr then
stopAtFirstNonSpace (strPos + 1, shd, absIdx + 1, stl)
else
absIdx - 1
end
fun loopNonSpace (strPos, shd, absIdx, stl) =
if strPos = String.size shd then
case stl of
shd :: stl => loopNonSpace (0, shd, absIdx, stl)
| [] => absIdx
else
let
val chr = String.sub (shd, strPos)
in
if chr = #"\n" then
absIdx - 1
else if Char.isSpace chr then
stopAtFirstNonSpace (strPos + 1, shd, absIdx + 1, stl)
else
loopNonSpace (strPos + 1, shd, absIdx + 1, stl)
end
fun loopSpace (strPos, shd, absIdx, stl) =
if strPos = String.size shd then
case stl of
shd :: stl => loopSpace (0, shd, absIdx, stl)
| [] => absIdx
else
let
val chr = String.sub (shd, strPos)
in
if chr = #"\n" then
absIdx - 1
else if Char.isSpace chr then
loopSpace (strPos + 1, shd, absIdx + 1, stl)
else
loopNonSpace (strPos + 1, shd, absIdx + 1, stl)
end
fun fStart (strPos, shd, _, absIdx, stl, _, _) =
let
val chr = String.sub (shd, strPos)
in
if chr = #"\n" then
absIdx
else if Char.isSpace chr then
loopSpace (strPos + 1, shd, absIdx + 1, stl)
else
loopNonSpace (strPos + 1, shd, absIdx + 1, stl)
end
end)
fun aroundWORDNext (lineGap, cursorIdx) =
AroundWORDNext.foldNext (lineGap, cursorIdx, ())
fun isCursorAtStartOfLine (lineGap: LineGap.t, cursorIdx) =
let
val {rightStrings, idx = bufferIdx, ...} = lineGap