add tests for 'diW' motion, and fix a bug in the implementation (contiguous spaces were not deleted properly)
This commit is contained in:
@@ -569,6 +569,56 @@ struct
|
|||||||
fun lastContiguousPunct (lineGap, cursorIdx) =
|
fun lastContiguousPunct (lineGap, cursorIdx) =
|
||||||
LastContiguousPunct.foldNext (lineGap, cursorIdx, ())
|
LastContiguousPunct.foldNext (lineGap, cursorIdx, ())
|
||||||
|
|
||||||
|
structure FirstContiguousNonSpace =
|
||||||
|
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 absIdx + 1
|
||||||
|
else loop (strPos - 1, shd, absIdx - 1, stl)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun fStart (strPos, shd, _, absIdx, stl, _, _) =
|
||||||
|
loop (strPos, shd, absIdx, stl)
|
||||||
|
end)
|
||||||
|
|
||||||
|
fun firstContiguousNonSpace (lineGap, cursorIdx) =
|
||||||
|
FirstContiguousNonSpace.foldPrev (lineGap, cursorIdx, ())
|
||||||
|
|
||||||
|
structure LastContiguousNonSpace =
|
||||||
|
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 absIdx - 1
|
||||||
|
else loop (strPos + 1, shd, absIdx + 1, stl)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun fStart (strPos, shd, _, absIdx, stl, _, _) =
|
||||||
|
loop (strPos, shd, absIdx, stl)
|
||||||
|
end)
|
||||||
|
|
||||||
|
fun lastContiguousNonSpace (lineGap, cursorIdx) =
|
||||||
|
LastContiguousNonSpace.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
|
||||||
|
|||||||
@@ -25,10 +25,7 @@ struct
|
|||||||
|
|
||||||
val buffer = LineGap.goToIdx (low, buffer)
|
val buffer = LineGap.goToIdx (low, buffer)
|
||||||
val low =
|
val low =
|
||||||
if Cursor.isOnNewlineAfterChr (buffer, low) then
|
if Cursor.isOnNewlineAfterChr (buffer, low) then low - 1 else low
|
||||||
low - 1
|
|
||||||
else
|
|
||||||
low
|
|
||||||
in
|
in
|
||||||
finishAfterDeletingBuffer (app, low, buffer, time, initialMsg)
|
finishAfterDeletingBuffer (app, low, buffer, time, initialMsg)
|
||||||
end
|
end
|
||||||
@@ -915,11 +912,6 @@ struct
|
|||||||
helpDeleteToMatch (app, newCursorIdx, cursorIdx, time)
|
helpDeleteToMatch (app, newCursorIdx, cursorIdx, time)
|
||||||
end
|
end
|
||||||
|
|
||||||
(* check if we are trying to delete from an empty buffer
|
|
||||||
* or a buffer which consists of only one character which is \n *)
|
|
||||||
fun canDeleteInsideOrAround (buffer, low, length) =
|
|
||||||
not (length = 1 andalso LineGap.substring (low, 1, buffer) = "\n")
|
|
||||||
|
|
||||||
fun deleteInsideWord (app: app_type, time) =
|
fun deleteInsideWord (app: app_type, time) =
|
||||||
let
|
let
|
||||||
val {buffer, cursorIdx, dfa, ...} = app
|
val {buffer, cursorIdx, dfa, ...} = app
|
||||||
@@ -959,26 +951,26 @@ 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.isSpace chr then
|
||||||
let
|
let
|
||||||
val initialMsg = Fn.initMsgs (low, length, buffer)
|
val low = Cursor.firstContiguousSpace (buffer, cursorIdx)
|
||||||
val buffer = LineGap.delete (low, length, buffer)
|
val high = Cursor.lastContiguousSpace (buffer, cursorIdx) + 1
|
||||||
val (buffer, searchList) = SearchList.build (buffer, dfa)
|
val length = high - low
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (low, buffer)
|
|
||||||
in
|
in
|
||||||
NormalFinish.buildTextAndClear
|
deleteAndFinish (app, low, length, buffer, time)
|
||||||
(app, buffer, low, searchList, initialMsg, time)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
app
|
let
|
||||||
|
val low = Cursor.firstContiguousNonSpace (buffer, cursorIdx)
|
||||||
|
val high = Cursor.lastContiguousNonSpace (buffer, cursorIdx) + 1
|
||||||
|
val length = high - low
|
||||||
|
in
|
||||||
|
deleteAndFinish (app, low, length, buffer, time)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fun finishAfterDeleteInside (app: app_type, origLow, high, time) =
|
fun finishAfterDeleteInside (app: app_type, origLow, high, time) =
|
||||||
|
|||||||
3
todo.md
3
todo.md
@@ -1,9 +1,8 @@
|
|||||||
# To-do list
|
# To-do list
|
||||||
|
|
||||||
- Add tests for:
|
- Add tests for:
|
||||||
- delete inside WORD
|
|
||||||
- Implement delete-around-word/WORD and test it
|
- Implement delete-around-word/WORD and test it
|
||||||
- Reimplement `%` motion and `d%` motion.
|
- Reimple `%` 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
|
||||||
- Reimplement `di<symbol>` and `da<symbol>`
|
- Reimplement `di<symbol>` and `da<symbol>`
|
||||||
|
|||||||
Reference in New Issue
Block a user