progress implementing help-prev-match for vector
This commit is contained in:
@@ -778,7 +778,8 @@ struct
|
|||||||
fun deleteToPrevMatch (app: app_type, count, time) =
|
fun deleteToPrevMatch (app: app_type, count, time) =
|
||||||
let
|
let
|
||||||
val {cursorIdx, searchList, ...} = app
|
val {cursorIdx, searchList, ...} = app
|
||||||
val newCursorIdx = SearchList.prevMatch (cursorIdx, searchList, count)
|
val newCursorIdx =
|
||||||
|
PersistentVector.prevMatch (cursorIdx, searchList, count)
|
||||||
in
|
in
|
||||||
if newCursorIdx = ~1 orelse newCursorIdx >= cursorIdx then
|
if newCursorIdx = ~1 orelse newCursorIdx >= cursorIdx then
|
||||||
NormalFinish.clearMode app
|
NormalFinish.clearMode app
|
||||||
|
|||||||
@@ -494,7 +494,8 @@ struct
|
|||||||
, visualScrollColumn
|
, visualScrollColumn
|
||||||
, ...
|
, ...
|
||||||
} = app
|
} = app
|
||||||
val newCursorIdx = PersistentVector.nextMatch (cursorIdx, searchList, count)
|
val newCursorIdx =
|
||||||
|
PersistentVector.nextMatch (cursorIdx, searchList, count)
|
||||||
in
|
in
|
||||||
if newCursorIdx = ~1 then
|
if newCursorIdx = ~1 then
|
||||||
NormalFinish.clearMode app
|
NormalFinish.clearMode app
|
||||||
@@ -506,7 +507,8 @@ struct
|
|||||||
fun moveToPrevMatch (app: app_type, count) =
|
fun moveToPrevMatch (app: app_type, count) =
|
||||||
let
|
let
|
||||||
val {cursorIdx, searchList, buffer, bufferModifyTime, ...} = app
|
val {cursorIdx, searchList, buffer, bufferModifyTime, ...} = app
|
||||||
val newCursorIdx = SearchList.prevMatch (cursorIdx, searchList, count)
|
val newCursorIdx =
|
||||||
|
PersistentVector.prevMatch (cursorIdx, searchList, count)
|
||||||
in
|
in
|
||||||
if newCursorIdx = ~1 then
|
if newCursorIdx = ~1 then
|
||||||
NormalFinish.clearMode app
|
NormalFinish.clearMode app
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ struct
|
|||||||
fun yankToPrevMatch (app: app_type, count) =
|
fun yankToPrevMatch (app: app_type, count) =
|
||||||
let
|
let
|
||||||
val {cursorIdx, searchList, buffer, ...} = app
|
val {cursorIdx, searchList, buffer, ...} = app
|
||||||
val low = SearchList.prevMatch (cursorIdx, searchList, count)
|
val low = PersistentVector.prevMatch (cursorIdx, searchList, count)
|
||||||
in
|
in
|
||||||
if low = ~1 orelse low >= cursorIdx then
|
if low = ~1 orelse low >= cursorIdx then
|
||||||
NormalFinish.clearMode app
|
NormalFinish.clearMode app
|
||||||
|
|||||||
@@ -110,41 +110,41 @@ struct
|
|||||||
LEAF (values, _) => Vector.sub (values, 0)
|
LEAF (values, _) => Vector.sub (values, 0)
|
||||||
| BRANCH (nodes, _) => getStart (Vector.sub (nodes, 0))
|
| BRANCH (nodes, _) => getStart (Vector.sub (nodes, 0))
|
||||||
|
|
||||||
fun helpNextMatch (cusorIdx, tree) =
|
fun helpNextMatch (cursorIdx, tree) =
|
||||||
case tree of
|
case tree of
|
||||||
LEAF (values, sizes) =>
|
LEAF (values, sizes) =>
|
||||||
let
|
let
|
||||||
val idx = BinSearch.equalOrMore (cusorIdx, sizes)
|
val idx = BinSearch.equalOrMore (cursorIdx, sizes)
|
||||||
in
|
in
|
||||||
if idx = ~1 then {start = ~1, finish = ~1}
|
if idx = ~1 then {start = ~1, finish = ~1}
|
||||||
else Vector.sub (values, idx)
|
else Vector.sub (values, idx)
|
||||||
end
|
end
|
||||||
| BRANCH (nodes, sizes) =>
|
| BRANCH (nodes, sizes) =>
|
||||||
let
|
let
|
||||||
val idx = BinSearch.equalOrMore (cusorIdx, sizes)
|
val idx = BinSearch.equalOrMore (cursorIdx, sizes)
|
||||||
in
|
in
|
||||||
if idx = ~1 then {start = ~1, finish = ~1}
|
if idx = ~1 then {start = ~1, finish = ~1}
|
||||||
else helpNextMatch (cusorIdx, Vector.sub (nodes, idx))
|
else helpNextMatch (cursorIdx, Vector.sub (nodes, idx))
|
||||||
end
|
end
|
||||||
|
|
||||||
fun startNextMatch (cusorIdx, tree) =
|
fun startNextMatch (cursorIdx, tree) =
|
||||||
case tree of
|
case tree of
|
||||||
LEAF (values, sizes) =>
|
LEAF (values, sizes) =>
|
||||||
if Vector.length sizes = 0 then
|
if Vector.length sizes = 0 then
|
||||||
{start = ~1, finish = ~1}
|
{start = ~1, finish = ~1}
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val idx = BinSearch.equalOrMore (cusorIdx, sizes)
|
val idx = BinSearch.equalOrMore (cursorIdx, sizes)
|
||||||
val idx = if idx = ~1 then 0 else idx
|
val idx = if idx = ~1 then 0 else idx
|
||||||
in
|
in
|
||||||
Vector.sub (values, idx)
|
Vector.sub (values, idx)
|
||||||
end
|
end
|
||||||
| BRANCH (nodes, sizes) =>
|
| BRANCH (nodes, sizes) =>
|
||||||
let
|
let
|
||||||
val idx = BinSearch.equalOrMore (cusorIdx, sizes)
|
val idx = BinSearch.equalOrMore (cursorIdx, sizes)
|
||||||
in
|
in
|
||||||
if idx = ~1 then {start = ~1, finish = ~1}
|
if idx = ~1 then {start = ~1, finish = ~1}
|
||||||
else helpNextMatch (cusorIdx, Vector.sub (nodes, idx))
|
else helpNextMatch (cursorIdx, Vector.sub (nodes, idx))
|
||||||
end
|
end
|
||||||
|
|
||||||
fun loopNextMatch (prevStart, prevFinish, tree, count) =
|
fun loopNextMatch (prevStart, prevFinish, tree, count) =
|
||||||
@@ -162,18 +162,18 @@ struct
|
|||||||
loopNextMatch (start, finish, tree, count - 1)
|
loopNextMatch (start, finish, tree, count - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun nextMatch (cusorIdx, tree, count) =
|
fun nextMatch (cursorIdx, tree, count) =
|
||||||
if isEmpty tree then
|
if isEmpty tree then
|
||||||
~1
|
~1
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val {start, finish} = startNextMatch (cusorIdx, tree)
|
val {start, finish} = startNextMatch (cursorIdx, tree)
|
||||||
in
|
in
|
||||||
if start = ~1 then
|
if start = ~1 then
|
||||||
let val {start, finish} = getStart tree
|
let val {start, finish} = getStart tree
|
||||||
in loopNextMatch (start, finish, tree, count - 1)
|
in loopNextMatch (start, finish, tree, count - 1)
|
||||||
end
|
end
|
||||||
else if cusorIdx >= start andalso cusorIdx <= finish then
|
else if cursorIdx >= start andalso cursorIdx <= finish then
|
||||||
loopNextMatch (start, finish, tree, count)
|
loopNextMatch (start, finish, tree, count)
|
||||||
else
|
else
|
||||||
loopNextMatch (start, finish, tree, count - 1)
|
loopNextMatch (start, finish, tree, count - 1)
|
||||||
@@ -185,4 +185,68 @@ struct
|
|||||||
Vector.sub (values, Vector.length values - 1)
|
Vector.sub (values, Vector.length values - 1)
|
||||||
| BRANCH (nodes, _) =>
|
| BRANCH (nodes, _) =>
|
||||||
getLast (Vector.sub (nodes, Vector.length nodes - 1))
|
getLast (Vector.sub (nodes, Vector.length nodes - 1))
|
||||||
|
|
||||||
|
fun helpPrevMatch (cursorIdx, tree) =
|
||||||
|
case tree of
|
||||||
|
LEAF (values, sizes) =>
|
||||||
|
let
|
||||||
|
val idx = BinSearch.equalOrMore (cursorIdx, sizes)
|
||||||
|
in
|
||||||
|
if idx < 0 then {start = ~1, finish = ~1}
|
||||||
|
else if idx = 0 then
|
||||||
|
let
|
||||||
|
val current = Vector.sub (values, 0)
|
||||||
|
in
|
||||||
|
current
|
||||||
|
end
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val current = Vector.sub (values, idx)
|
||||||
|
val prev = Vector.sub (values, idx - 1)
|
||||||
|
in
|
||||||
|
if cursorIdx > #start current then
|
||||||
|
current
|
||||||
|
else
|
||||||
|
prev
|
||||||
|
end
|
||||||
|
end
|
||||||
|
| BRANCH (nodes, sizes) =>
|
||||||
|
let
|
||||||
|
val idx = BinSearch.equalOrMore (cursorIdx, sizes)
|
||||||
|
in
|
||||||
|
if idx < 0 then {start = ~1, finish = ~1}
|
||||||
|
else helpPrevMatch (cursorIdx, Vector.sub (nodes, idx))
|
||||||
|
end
|
||||||
|
|
||||||
|
fun loopPrevMatch (prevStart, tree, count) =
|
||||||
|
if count = 0 then
|
||||||
|
prevStart
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val {start, finish} = helpPrevMatch (prevStart - 1, tree)
|
||||||
|
in
|
||||||
|
if start = ~1 then
|
||||||
|
let val {start, finish} = getLast tree
|
||||||
|
in loopPrevMatch (start, tree, count - 1)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
loopPrevMatch (start, tree, count - 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun prevMatch (cursorIdx, tree, count) =
|
||||||
|
if isEmpty tree then
|
||||||
|
~1
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val {start, finish} = helpPrevMatch (cursorIdx, tree)
|
||||||
|
in
|
||||||
|
if start = ~1 then
|
||||||
|
let val {start, finish} = getLast tree
|
||||||
|
in loopPrevMatch (start, tree, count - 1)
|
||||||
|
end
|
||||||
|
else if cursorIdx >= start andalso cursorIdx <= finish then
|
||||||
|
loopPrevMatch (start, tree, count)
|
||||||
|
else
|
||||||
|
loopPrevMatch (start, tree, count - 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -121,6 +121,4 @@ struct
|
|||||||
)
|
)
|
||||||
else
|
else
|
||||||
(buffer, PersistentVector.empty)
|
(buffer, PersistentVector.empty)
|
||||||
|
|
||||||
fun prevMatch (cursorIdx, searchList, count) = raise Fail "todo: reimplement"
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user