pass failing tests for 'dj' motion
This commit is contained in:
@@ -374,12 +374,65 @@ struct
|
|||||||
NormalModeWith.bufferMsgsAndMode (app, buffer, [], NORMAL_MODE "")
|
NormalModeWith.bufferMsgsAndMode (app, buffer, [], NORMAL_MODE "")
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val () = print "not on last line so have to delete\n"
|
val buffer = LineGap.goToIdx (endLineIdx, buffer)
|
||||||
val () = print
|
|
||||||
("startLine = " ^ Int.toString startLine ^ "; endLine = "
|
(* right now, endLineIdx may be on a newline.
|
||||||
^ Int.toString endLine ^ "\n")
|
* If it is, we want to delete that newline too,
|
||||||
|
* and in that case, we increment by 1 to do so.
|
||||||
|
* However, we don't want to delete the last newline in the file
|
||||||
|
* so we don't increment in that case.
|
||||||
|
* Edge case: if the startIdx also begins after a newline
|
||||||
|
* then it is okay for us to delete the newline at the end of the file
|
||||||
|
* because there will already be a newline at the end of the file
|
||||||
|
* after the deletion. *)
|
||||||
|
val endsOnNewline = Cursor.isCursorAtStartOfLine (buffer, endLineIdx)
|
||||||
|
|
||||||
|
val buffer = LineGap.goToIdx (startIdx, buffer)
|
||||||
|
val startsAfterNewline =
|
||||||
|
startIdx > 0 andalso Cursor.isPrevChrStartOfLine (buffer, startIdx)
|
||||||
|
|
||||||
|
val endLineIdx =
|
||||||
|
if endsOnNewline then
|
||||||
|
if endLineIdx = #textLength buffer - 1 then
|
||||||
|
if startsAfterNewline then endLineIdx + 1 else endLineIdx
|
||||||
|
else
|
||||||
|
endLineIdx + 1
|
||||||
|
else
|
||||||
|
endLineIdx
|
||||||
|
|
||||||
|
val length = endLineIdx - startIdx
|
||||||
|
|
||||||
|
(* perform the actual deletion *)
|
||||||
|
val buffer = LineGap.goToIdx (endLineIdx, buffer)
|
||||||
|
val initialMsg = Fn.initMsgs (startIdx, length, buffer)
|
||||||
|
val buffer = LineGap.delete (startIdx, length, buffer)
|
||||||
|
|
||||||
|
(* if we deleted end of file, then we have to move the cursorIdx
|
||||||
|
* to the first column of the now-last line *)
|
||||||
|
val newEndIdx = #textLength buffer - 1
|
||||||
in
|
in
|
||||||
raise Fail ""
|
if startIdx >= newEndIdx then
|
||||||
|
let
|
||||||
|
val buffer = LineGap.goToIdx (newEndIdx, buffer)
|
||||||
|
in
|
||||||
|
if Cursor.isOnNewlineAfterChr (buffer, newEndIdx) then
|
||||||
|
let
|
||||||
|
val buffer = LineGap.goToIdx (newEndIdx - 1, buffer)
|
||||||
|
val newCursorIdx = Cursor.vi0 (buffer, newEndIdx - 1)
|
||||||
|
in
|
||||||
|
finishAfterDeletingBuffer
|
||||||
|
(app, newCursorIdx, buffer, time, initialMsg)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val newCursorIdx = Cursor.vi0 (buffer, newEndIdx)
|
||||||
|
in
|
||||||
|
finishAfterDeletingBuffer
|
||||||
|
(app, newCursorIdx, buffer, time, initialMsg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -349,7 +349,7 @@ struct
|
|||||||
val app = AppWith.idx (app, originalIdx)
|
val app = AppWith.idx (app, originalIdx)
|
||||||
|
|
||||||
(* act *)
|
(* act *)
|
||||||
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "dl")
|
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "dj")
|
||||||
|
|
||||||
(* assert *)
|
(* assert *)
|
||||||
val actualString = LineGap.toString buffer
|
val actualString = LineGap.toString buffer
|
||||||
@@ -374,11 +374,11 @@ struct
|
|||||||
val app = AppWith.idx (app, originalIdx)
|
val app = AppWith.idx (app, originalIdx)
|
||||||
|
|
||||||
(* act *)
|
(* act *)
|
||||||
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "dl")
|
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "dj")
|
||||||
|
|
||||||
(* assert *)
|
(* assert *)
|
||||||
val actualString = LineGap.toString buffer
|
val actualString = LineGap.toString buffer
|
||||||
val expectedString = "bye world\n"
|
val expectedString = "hello\n"
|
||||||
val stringIsExpected = actualString = expectedString
|
val stringIsExpected = actualString = expectedString
|
||||||
|
|
||||||
val expectedCursorIdx = 0
|
val expectedCursorIdx = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user