fix minor bug in Cursor.matchPair fuunction; depending on chr at strIdx, we might want to iterate on the leftStrings or on the rightStrings. Before, we iterated on the rightStrings only, but now we iterate on whichever is appropriate

This commit is contained in:
2024-10-31 11:50:18 +00:00
parent fe317ca220
commit 25f06b1f9a
2 changed files with 47 additions and 51 deletions

View File

@@ -1611,7 +1611,7 @@ struct
if strPos < 0 then if strPos < 0 then
case stl of case stl of
hd :: tl => hd :: tl =>
helpMatchPairNext helpMatchPairPrev
( String.size hd - 1, hd, absIdx, tl, origIdx ( String.size hd - 1, hd, absIdx, tl, origIdx
, openChr, openNum, closeChr, closeNum , openChr, openNum, closeChr, closeNum
) )
@@ -1632,53 +1632,49 @@ struct
) )
end end
fun startMatchPair (strIdx, shd, stl, cursorIdx) = fun startMatchPair (strIdx, shd, leftStrings, rightStrings, cursorIdx) =
let case String.sub (shd, strIdx) of
val chr = String.sub (shd, strIdx)
in
(case chr of
#"(" => #"(" =>
helpMatchPairNext helpMatchPairNext
( strIdx + 1, shd, cursorIdx + 1, stl, cursorIdx ( strIdx + 1, shd, cursorIdx + 1, rightStrings, cursorIdx
, #"(", 1, #")", 0 , #"(", 1, #")", 0
) )
| #")" => | #")" =>
helpMatchPairPrev helpMatchPairPrev
( strIdx - 1, shd, cursorIdx - 1, stl, cursorIdx ( strIdx - 1, shd, cursorIdx - 1, leftStrings, cursorIdx
, #"(", 0, #")", 1 , #"(", 0, #")", 1
) )
| #"[" => | #"[" =>
helpMatchPairNext helpMatchPairNext
( strIdx + 1, shd, cursorIdx + 1, stl, cursorIdx ( strIdx + 1, shd, cursorIdx + 1, rightStrings, cursorIdx
, #"[", 1, #"]", 0 , #"[", 1, #"]", 0
) )
| #"]" => | #"]" =>
helpMatchPairPrev helpMatchPairPrev
( strIdx - 1, shd, cursorIdx - 1, stl, cursorIdx ( strIdx - 1, shd, cursorIdx - 1, leftStrings, cursorIdx
, #"[", 0, #"]", 1 , #"[", 0, #"]", 1
) )
| #"{" => | #"{" =>
helpMatchPairNext helpMatchPairNext
( strIdx + 1, shd, cursorIdx + 1, stl, cursorIdx ( strIdx + 1, shd, cursorIdx + 1, rightStrings, cursorIdx
, #"{", 1, #"}", 0 , #"{", 1, #"}", 0
) )
| #"}" => | #"}" =>
helpMatchPairPrev helpMatchPairPrev
( strIdx - 1, shd, cursorIdx - 1, stl, cursorIdx ( strIdx - 1, shd, cursorIdx - 1, leftStrings, cursorIdx
, #"{", 0, #"}", 1 , #"{", 0, #"}", 1
) )
| #"<" => | #"<" =>
helpMatchPairNext helpMatchPairNext
( strIdx + 1, shd, cursorIdx + 1, stl, cursorIdx ( strIdx + 1, shd, cursorIdx + 1, rightStrings, cursorIdx
, #"<", 1, #">", 0 , #"<", 1, #">", 0
) )
| #">" => | #">" =>
helpMatchPairPrev helpMatchPairPrev
( strIdx - 1, shd, cursorIdx - 1, stl, cursorIdx ( strIdx - 1, shd, cursorIdx - 1, leftStrings, cursorIdx
, #"<", 0, #">", 1 , #"<", 0, #">", 1
) )
| _ => cursorIdx) | _ => cursorIdx
end
fun matchPair (lineGap: LineGap.t, cursorIdx) = fun matchPair (lineGap: LineGap.t, cursorIdx) =
let let
@@ -1692,7 +1688,7 @@ struct
in in
if strIdx < String.size shd then if strIdx < String.size shd then
(* strIdx is in this string *) (* strIdx is in this string *)
startMatchPair (strIdx, shd, stl, cursorIdx) startMatchPair (strIdx, shd, leftStrings, stl, cursorIdx)
else else
(* strIdx is in tl *) (* strIdx is in tl *)
(case stl of (case stl of
@@ -1701,7 +1697,7 @@ struct
val strIdx = strIdx - String.size shd val strIdx = strIdx - String.size shd
val leftStrings = shd :: leftStrings val leftStrings = shd :: leftStrings
in in
startMatchPair (strIdx, stlhd, leftStrings, cursorIdx) startMatchPair (strIdx, stlhd, leftStrings, stltl, cursorIdx)
end end
| [] => cursorIdx) | [] => cursorIdx)
end end

BIN
shf

Binary file not shown.