reimplemen 'diw' motion to fix failing test
This commit is contained in:
165
fcore/cursor.sml
165
fcore/cursor.sml
@@ -46,7 +46,6 @@ struct
|
|||||||
MakeIfCharFolderPrev
|
MakeIfCharFolderPrev
|
||||||
(struct
|
(struct
|
||||||
type env = unit
|
type env = unit
|
||||||
val fStart = startVi0
|
|
||||||
fun fStart (strPos, shd, lhd, absIdx, stl, ltl, _) =
|
fun fStart (strPos, shd, lhd, absIdx, stl, ltl, _) =
|
||||||
startVi0 (strPos, shd, lhd, absIdx, stl, ltl)
|
startVi0 (strPos, shd, lhd, absIdx, stl, ltl)
|
||||||
end)
|
end)
|
||||||
@@ -406,6 +405,170 @@ struct
|
|||||||
| [] => cursorIdx
|
| [] => cursorIdx
|
||||||
end
|
end
|
||||||
|
|
||||||
|
structure FirstContiguousAlpha =
|
||||||
|
MakeIfCharFolderPrev
|
||||||
|
(struct
|
||||||
|
type env = unit
|
||||||
|
|
||||||
|
fun loop (strPos, shd, absIdx, stl) =
|
||||||
|
if strPos < 0 then
|
||||||
|
case stl of
|
||||||
|
shd :: stl => loop (String.size shd - 1, shd, absIdx, stl)
|
||||||
|
| [] => 0
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val chr = String.sub (shd, strPos)
|
||||||
|
in
|
||||||
|
if Char.isAlphaNum chr orelse chr = #"_" then
|
||||||
|
loop (strPos - 1, shd, absIdx - 1, stl)
|
||||||
|
else
|
||||||
|
absIdx + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
fun fStart (strPos, shd, _, absIdx, stl, _, _) =
|
||||||
|
loop (strPos, shd, absIdx, stl)
|
||||||
|
end)
|
||||||
|
|
||||||
|
fun firstContiguousAlpha (lineGap, cursorIdx) =
|
||||||
|
FirstContiguousAlpha.foldPrev (lineGap, cursorIdx, ())
|
||||||
|
|
||||||
|
structure LastContiguousAlpha =
|
||||||
|
MakeIfCharFolderNext
|
||||||
|
(struct
|
||||||
|
type env = unit
|
||||||
|
|
||||||
|
fun loop (strPos, shd, absIdx, stl) =
|
||||||
|
if strPos = String.size shd then
|
||||||
|
case stl of
|
||||||
|
shd :: stl => loop (0, shd, absIdx, stl)
|
||||||
|
| [] => Int.max (0, absIdx - 1)
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val chr = String.sub (shd, strPos)
|
||||||
|
in
|
||||||
|
if Char.isAlphaNum chr orelse chr = #"_" then
|
||||||
|
loop (strPos + 1, shd, absIdx + 1, stl)
|
||||||
|
else
|
||||||
|
absIdx - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
fun fStart (strPos, shd, _, absIdx, stl, _, _) =
|
||||||
|
loop (strPos, shd, absIdx, stl)
|
||||||
|
end)
|
||||||
|
|
||||||
|
fun lastContiguousAlpha (lineGap, cursorIdx) =
|
||||||
|
LastContiguousAlpha.foldNext (lineGap, cursorIdx, ())
|
||||||
|
|
||||||
|
structure FirstContiguousSpace =
|
||||||
|
MakeIfCharFolderPrev
|
||||||
|
(struct
|
||||||
|
type env = unit
|
||||||
|
|
||||||
|
fun loop (strPos, shd, absIdx, stl) =
|
||||||
|
if strPos < 0 then
|
||||||
|
case stl of
|
||||||
|
shd :: stl => loop (String.size shd - 1, shd, absIdx, stl)
|
||||||
|
| [] => 0
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val chr = String.sub (shd, strPos)
|
||||||
|
in
|
||||||
|
if Char.isSpace chr then
|
||||||
|
if chr = #"\n" then absIdx + 1
|
||||||
|
else loop (strPos - 1, shd, absIdx - 1, stl)
|
||||||
|
else
|
||||||
|
absIdx + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
fun fStart (strPos, shd, _, absIdx, stl, _, _) =
|
||||||
|
loop (strPos, shd, absIdx, stl)
|
||||||
|
end)
|
||||||
|
|
||||||
|
fun firstContiguousSpace (lineGap, cursorIdx) =
|
||||||
|
FirstContiguousSpace.foldPrev (lineGap, cursorIdx, ())
|
||||||
|
|
||||||
|
structure LastContiguousSpace =
|
||||||
|
MakeIfCharFolderNext
|
||||||
|
(struct
|
||||||
|
type env = unit
|
||||||
|
|
||||||
|
fun loop (strPos, shd, absIdx, stl) =
|
||||||
|
if strPos = String.size shd then
|
||||||
|
case stl of
|
||||||
|
shd :: stl => loop (0, shd, absIdx, stl)
|
||||||
|
| [] => Int.max (0, absIdx - 1)
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val chr = String.sub (shd, strPos)
|
||||||
|
in
|
||||||
|
if Char.isSpace chr then
|
||||||
|
if chr = #"\n" then absIdx - 1
|
||||||
|
else loop (strPos + 1, shd, absIdx + 1, stl)
|
||||||
|
else
|
||||||
|
absIdx - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
fun fStart (strPos, shd, _, absIdx, stl, _, _) =
|
||||||
|
loop (strPos, shd, absIdx, stl)
|
||||||
|
end)
|
||||||
|
|
||||||
|
fun lastContiguousSpace (lineGap, cursorIdx) =
|
||||||
|
LastContiguousSpace.foldNext (lineGap, cursorIdx, ())
|
||||||
|
|
||||||
|
structure FirstContiguousPunct =
|
||||||
|
MakeIfCharFolderPrev
|
||||||
|
(struct
|
||||||
|
type env = unit
|
||||||
|
|
||||||
|
fun loop (strPos, shd, absIdx, stl) =
|
||||||
|
if strPos < 0 then
|
||||||
|
case stl of
|
||||||
|
shd :: stl => loop (String.size shd - 1, shd, absIdx, stl)
|
||||||
|
| [] => 0
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val chr = String.sub (shd, strPos)
|
||||||
|
in
|
||||||
|
if Char.isAlphaNum chr orelse chr = #"_" orelse Char.isSpace chr then
|
||||||
|
absIdx + 1
|
||||||
|
else
|
||||||
|
loop (strPos - 1, shd, absIdx - 1, stl)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun fStart (strPos, shd, _, absIdx, stl, _, _) =
|
||||||
|
loop (strPos, shd, absIdx, stl)
|
||||||
|
end)
|
||||||
|
|
||||||
|
fun firstContiguousPunct (lineGap, cursorIdx) =
|
||||||
|
FirstContiguousPunct.foldPrev (lineGap, cursorIdx, ())
|
||||||
|
|
||||||
|
structure LastContiguousPunct =
|
||||||
|
MakeIfCharFolderNext
|
||||||
|
(struct
|
||||||
|
type env = unit
|
||||||
|
|
||||||
|
fun loop (strPos, shd, absIdx, stl) =
|
||||||
|
if strPos = String.size shd then
|
||||||
|
case stl of
|
||||||
|
shd :: stl => loop (0, shd, absIdx, stl)
|
||||||
|
| [] => Int.max (0, absIdx - 1)
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val chr = String.sub (shd, strPos)
|
||||||
|
in
|
||||||
|
if Char.isAlphaNum chr orelse chr = #"_" orelse Char.isSpace chr then
|
||||||
|
absIdx - 1
|
||||||
|
else
|
||||||
|
loop (strPos + 1, shd, absIdx + 1, stl)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun fStart (strPos, shd, _, absIdx, stl, _, _) =
|
||||||
|
loop (strPos, shd, absIdx, stl)
|
||||||
|
end)
|
||||||
|
|
||||||
|
fun lastContiguousPunct (lineGap, cursorIdx) =
|
||||||
|
LastContiguousPunct.foldNext (lineGap, cursorIdx, ())
|
||||||
|
|
||||||
(* Prerequisite: lineGap is moved to cursorIdx *)
|
(* Prerequisite: lineGap is moved to cursorIdx *)
|
||||||
fun isCursorAtStartOfLine (lineGap: LineGap.t, cursorIdx) =
|
fun isCursorAtStartOfLine (lineGap: LineGap.t, cursorIdx) =
|
||||||
let
|
let
|
||||||
|
|||||||
@@ -917,30 +917,35 @@ struct
|
|||||||
let
|
let
|
||||||
val {buffer, cursorIdx, dfa, ...} = app
|
val {buffer, cursorIdx, dfa, ...} = app
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
val chr = LineGap.sub (cursorIdx, buffer)
|
||||||
val low = Cursor.prevWordStrict (buffer, cursorIdx, 1)
|
|
||||||
val high = Cursor.endOfWordStrict (buffer, cursorIdx, 1) + 1
|
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (high, buffer)
|
|
||||||
val length = high - low
|
|
||||||
in
|
in
|
||||||
if canDeleteInsideOrAround (buffer, low, length) then
|
if chr = #"\n" then
|
||||||
|
NormalFinish.clearMode app
|
||||||
|
else if Char.isAlphaNum chr orelse chr = #"_" then
|
||||||
let
|
let
|
||||||
val buffer = LineGap.goToIdx (high, buffer)
|
val low = Cursor.firstContiguousAlpha (buffer, cursorIdx)
|
||||||
|
val high = Cursor.lastContiguousAlpha (buffer, cursorIdx) + 1
|
||||||
val length = high - low
|
val length = high - low
|
||||||
val initialMsg = Fn.initMsgs (low, length, buffer)
|
|
||||||
|
|
||||||
val buffer = LineGap.delete (low, length, buffer)
|
|
||||||
|
|
||||||
val (buffer, searchList) = SearchList.build (buffer, dfa)
|
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (low, buffer)
|
|
||||||
in
|
in
|
||||||
NormalFinish.buildTextAndClear
|
deleteAndFinish (app, low, length, buffer, time)
|
||||||
(app, buffer, low, searchList, initialMsg, time)
|
end
|
||||||
|
else if Char.isSpace chr then
|
||||||
|
let
|
||||||
|
val low = Cursor.firstContiguousSpace (buffer, cursorIdx)
|
||||||
|
val high = Cursor.lastContiguousSpace (buffer, cursorIdx) + 1
|
||||||
|
val length = high - low
|
||||||
|
in
|
||||||
|
deleteAndFinish (app, low, length, buffer, time)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
app
|
(* char is punct *)
|
||||||
|
let
|
||||||
|
val low = Cursor.firstContiguousPunct (buffer, cursorIdx)
|
||||||
|
val high = Cursor.lastContiguousPunct (buffer, cursorIdx) + 1
|
||||||
|
val length = high - low
|
||||||
|
in
|
||||||
|
deleteAndFinish (app, low, length, buffer, time)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fun deleteInsideWORD (app: app_type, time) =
|
fun deleteInsideWORD (app: app_type, time) =
|
||||||
|
|||||||
4
todo.md
4
todo.md
@@ -1,8 +1,8 @@
|
|||||||
# To-do list
|
# To-do list
|
||||||
|
|
||||||
- Add tests for:
|
- Add tests for:
|
||||||
- delete inside word
|
- delete inside WORD
|
||||||
- Implement delete-around-word and test it
|
- Implement delete-around-word/WORD and test it
|
||||||
- Reimplement `%` motion and `d%` motion.
|
- Reimplement `%` motion and `d%` motion.
|
||||||
- They should both search for the next character in any pair, the same way in Vim
|
- They should both search for the next character in any pair, the same way in Vim
|
||||||
- Add tests for reimplemented movements and motions
|
- Add tests for reimplemented movements and motions
|
||||||
|
|||||||
Reference in New Issue
Block a user