bugfix: in search-list.sml's 'delRightFromHere' function, make sure we preserve the last part of the vector when finish < last

This commit is contained in:
2024-11-16 09:05:47 +00:00
parent 436b3e0d92
commit f2b4f256ec
3 changed files with 19 additions and 9 deletions

View File

@@ -421,7 +421,7 @@ struct
(* delete char at cursor and then decrement cursorIdx by 1 (* delete char at cursor and then decrement cursorIdx by 1
* if cursorIdx is not 0 *) * if cursorIdx is not 0 *)
val buffer = LineGap.delete (cursorIdx, 1, buffer) val buffer = LineGap.delete (cursorIdx, 1, buffer)
val searchList = SearchList.delete (cursorIdx, 1, searchList) val searchList = SearchList.delete (cursorIdx, 1, #searchString app, searchList)
val searchList = SearchList.mapFrom (cursorIdx, ~1, searchList) val searchList = SearchList.mapFrom (cursorIdx, ~1, searchList)
val cursorIdx = val cursorIdx =
@@ -436,7 +436,7 @@ struct
else else
let let
val buffer = LineGap.delete (cursorIdx, 1, buffer) val buffer = LineGap.delete (cursorIdx, 1, buffer)
val searchList = SearchList.delete (cursorIdx, 1, searchList) val searchList = SearchList.delete (cursorIdx, 1, #searchString app, searchList)
val searchList = SearchList.mapFrom (cursorIdx, ~1, searchList) val searchList = SearchList.mapFrom (cursorIdx, ~1, searchList)
in in
helpRemoveChr (app, buffer, searchList, cursorIdx, count - 1) helpRemoveChr (app, buffer, searchList, cursorIdx, count - 1)

View File

@@ -5,7 +5,7 @@ sig
val insert: int * t -> t val insert: int * t -> t
val append: int * t -> t val append: int * t -> t
val delete: int * int * t -> t val delete: int * int * string * t -> t
val goToNum: int * t -> t val goToNum: int * t -> t
val mapFrom: int * int * t -> t val mapFrom: int * int * t -> t
@@ -220,8 +220,9 @@ struct
{left = left, right = right} {left = left, right = right}
else if finish < last then else if finish < last then
let let
val delpoint = BinSearch.equalOrMore (finish, hd) val delstart = BinSearch.equalOrMore (finish, hd)
val newHd = VectorSlice.slice (hd, 0, SOME delpoint) val dellength = Vector.length hd - delstart
val newHd = VectorSlice.slice (hd, delstart, SOME dellength)
val newHd = VectorSlice.vector newHd val newHd = VectorSlice.vector newHd
in in
{left = left, right = joinStartOfRight (newHd, right)} {left = left, right = joinStartOfRight (newHd, right)}
@@ -230,7 +231,8 @@ struct
(* finish = last *) (* finish = last *)
{left = left, right = tl} {left = left, right = tl}
end end
| [] => {left = left, right = right} | [] =>
{left = left, right = right}
fun moveRightAndDelete (start, finish, left, right) = fun moveRightAndDelete (start, finish, left, right) =
case right of case right of
@@ -411,6 +413,7 @@ struct
else if start = rfirst then else if start = rfirst then
delRightFromHere (finish, left, right) delRightFromHere (finish, left, right)
else else
(* finish > rfirst *)
moveRightAndDelete (start, finish, left, right) moveRightAndDelete (start, finish, left, right)
end end
| [] => | [] =>
@@ -429,9 +432,16 @@ struct
(* left and right are both empty *) (* left and right are both empty *)
{left = left, right = right}) {left = left, right = right})
fun delete (start, length, {left, right}: t) = fun delete (start, length, searchString, {left, right}: t) =
if length > 0 then del (start, start + length, left, right) if length > 0 then
else {left = left, right = right} let
val finish = start + length
val start = start - String.size searchString + 1
in
del (start, finish, left, right)
end
else
{left = left, right = right}
(* go all the way to the end of the list, mapping each hd, (* go all the way to the end of the list, mapping each hd,
* joining the hd to the left, * joining the hd to the left,

BIN
shf

Binary file not shown.