in search-list.sml: fix 'delRightFromHere' and 'delLeftFromHere' functions which joined newHd with left/right, rather than the tl, and therefore added new numbers to the list, which is incorrect behaviour. Fixed this by using joining with 'tl' rather than left/right. In build-search-list.sml: make fromRange function return tuple instead of an instance of app. Finally, in app-update.sml: progress towards refactoring 'helpRemoveChr' function to map and delete from searchList as desired.

This commit is contained in:
2024-11-17 09:25:01 +00:00
parent f7cc2d4740
commit e90df37b43
4 changed files with 26 additions and 12 deletions

View File

@@ -420,9 +420,14 @@ struct
let let
(* 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 {searchString, ...} = app
val buffer = LineGap.delete (cursorIdx, 1, buffer) val buffer = LineGap.delete (cursorIdx, 1, buffer)
val searchList = SearchList.delete (cursorIdx, 1, #searchString app, searchList)
val searchList = SearchList.delete (cursorIdx, 1, searchString, searchList)
val searchList = SearchList.mapFrom (cursorIdx, ~1, searchList) val searchList = SearchList.mapFrom (cursorIdx, ~1, searchList)
val (buffer, searchList) =
BuildSearchList.fromRange
(cursorIdx, 1, buffer, searchString, searchList)
val cursorIdx = val cursorIdx =
if if
@@ -435,9 +440,14 @@ struct
end end
else else
let let
val {searchString, ...} = app
val buffer = LineGap.delete (cursorIdx, 1, buffer) val buffer = LineGap.delete (cursorIdx, 1, buffer)
val searchList = SearchList.delete (cursorIdx, 1, #searchString app, searchList)
val searchList = SearchList.delete (cursorIdx, 1, searchString, searchList)
val searchList = SearchList.mapFrom (cursorIdx, ~1, searchList) val searchList = SearchList.mapFrom (cursorIdx, ~1, searchList)
val (buffer, searchList) =
BuildSearchList.fromRange
(cursorIdx, 1, buffer, searchString, searchList)
in in
helpRemoveChr (app, buffer, searchList, cursorIdx, count - 1) helpRemoveChr (app, buffer, searchList, cursorIdx, count - 1)
end end

View File

@@ -81,9 +81,11 @@ struct
(* searches for matchedIdx within a range from the buffer instead of from start *) (* searches for matchedIdx within a range from the buffer instead of from start *)
fun helpFromRange fun helpFromRange
(app, origIdx, curIdx, finishIdx, buffer, searchString, searchList) = (origIdx, curIdx, finishIdx, buffer, searchString, searchList) =
let let
val buffer = LineGap.goToIdx (curIdx, buffer) val {idx = bufferIdx, rightStrings, ...} = buffer in val buffer = LineGap.goToIdx (curIdx, buffer)
val {idx = bufferIdx, rightStrings, ...} = buffer
in
case nextMatch (bufferIdx, curIdx, rightStrings, searchString) of case nextMatch (bufferIdx, curIdx, rightStrings, searchString) of
SOME matchedIdx => SOME matchedIdx =>
if matchedIdx > finishIdx then if matchedIdx > finishIdx then
@@ -91,14 +93,14 @@ struct
val buffer = LineGap.goToIdx (origIdx, buffer) val buffer = LineGap.goToIdx (origIdx, buffer)
val searchList = SearchList.goToNum (origIdx, searchList) val searchList = SearchList.goToNum (origIdx, searchList)
in in
AppWith.searchList (app, searchList, buffer, searchString) (buffer, searchList)
end end
else else
let let
val searchList = SearchList.insert (matchedIdx, searchList) val searchList = SearchList.insert (matchedIdx, searchList)
in in
helpFromRange helpFromRange
( app, origIdx, matchedIdx + 1, finishIdx ( origIdx, matchedIdx + 1, finishIdx
, buffer, searchString, searchList , buffer, searchString, searchList
) )
end end
@@ -107,15 +109,16 @@ struct
val buffer = LineGap.goToIdx (origIdx, buffer) val buffer = LineGap.goToIdx (origIdx, buffer)
val searchList = SearchList.goToNum (origIdx, searchList) val searchList = SearchList.goToNum (origIdx, searchList)
in in
AppWith.searchList (app, searchList, buffer, searchString) (buffer, searchList)
end end
end end
fun fromRange (app, startIdx, finishIdx, buffer, searchString, searchList) = fun fromRange (startIdx, length, buffer, searchString, searchList) =
let let
val buffer = LineGap.goToIdx (startIdx, buffer) val finishIdx = startIdx + length + String.size searchString
val bufferIdx = startIdx - String.size searchString
in in
helpFromRange helpFromRange
(app, startIdx, startIdx, finishIdx, buffer, searchString, searchList) (startIdx, bufferIdx, finishIdx, buffer, searchString, searchList)
end end
end end

View File

@@ -9,6 +9,7 @@ sig
val goToNum: int * t -> t val goToNum: int * t -> t
val mapFrom: int * int * t -> t val mapFrom: int * int * t -> t
val printlst: t -> unit
end end
structure SearchList :> SEARCH_LIST = structure SearchList :> SEARCH_LIST =
@@ -233,7 +234,7 @@ struct
val newHd = VectorSlice.slice (hd, delstart, SOME dellength) 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, tl)}
end end
else else
(* finish = last *) (* finish = last *)
@@ -317,7 +318,7 @@ struct
val newHd = VectorSlice.slice (hd, delpoint, SOME newLength) val newHd = VectorSlice.slice (hd, delpoint, SOME newLength)
val newHd = VectorSlice.vector newHd val newHd = VectorSlice.vector newHd
in in
{left = joinEndOfLeft (newHd, left), right = right} {left = joinEndOfLeft (newHd, tl), right = right}
end end
else else
(* start = first *) (* start = first *)

BIN
shf

Binary file not shown.