Adding findPrev for searching backwards to textEditor. Fixing findNext bug
This commit is contained in:
parent
4a62774a57
commit
d36f694d80
1 changed files with 38 additions and 12 deletions
|
|
@ -1,5 +1,13 @@
|
||||||
@textEditor
|
@textEditor
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
# r to repalce
|
||||||
|
# O to open new line above
|
||||||
|
# s to seek
|
||||||
|
# w / b bug, can't select `textEditor` at start of line
|
||||||
|
# a to append
|
||||||
|
# smart case searching
|
||||||
|
|
||||||
textEditor = name \
|
textEditor = name \
|
||||||
# defaults = {};
|
# defaults = {};
|
||||||
# c = { ...defaults, ...config };
|
# c = { ...defaults, ...config };
|
||||||
|
|
@ -136,7 +144,6 @@ textEditor = name \
|
||||||
{ state = state, emit = [rebindAt [buffersKey, name] content] };
|
{ state = state, emit = [rebindAt [buffersKey, name] content] };
|
||||||
|
|
||||||
apply = state \
|
apply = state \
|
||||||
# content = name & " = " & (join "\n" state.lines) & ";";
|
|
||||||
content = (join "\n" state.lines);
|
content = (join "\n" state.lines);
|
||||||
result = eval! content;
|
result = eval! content;
|
||||||
_ = debug! "apply" [content, result];
|
_ = debug! "apply" [content, result];
|
||||||
|
|
@ -243,7 +250,7 @@ textEditor = name \
|
||||||
{ state = newState, emit = [] };
|
{ state = newState, emit = [] };
|
||||||
|
|
||||||
findNext = query lines row col \
|
findNext = query lines row col \
|
||||||
rest = strIndexOf query (nth row lines ~ unwrapOr "") (col + 1);
|
rest = strIndexOf query (nth row lines ~ unwrapOr "") col;
|
||||||
rest
|
rest
|
||||||
| Some c \ { row = row, col = c }
|
| Some c \ { row = row, col = c }
|
||||||
| None \ (
|
| None \ (
|
||||||
|
|
@ -259,7 +266,23 @@ textEditor = name \
|
||||||
| None \ findInLines (r + 1)));
|
| None \ findInLines (r + 1)));
|
||||||
findInLines (row + 1));
|
findInLines (row + 1));
|
||||||
|
|
||||||
# TODO: findPrev
|
findPrev = query lines row col \
|
||||||
|
line = slice (nth row lines ~ unwrapOr "") 0 col;
|
||||||
|
rest = strLastIndexOf query line;
|
||||||
|
rest
|
||||||
|
| Some c \ { row = row, col = c }
|
||||||
|
| None \ (
|
||||||
|
findInLines = r \
|
||||||
|
r < 0
|
||||||
|
| True \ findInLines (len lines - 1) # wrap to bottom
|
||||||
|
| False \ (r == row
|
||||||
|
| True \ (strLastIndexOf query (nth row lines ~ unwrapOr "")
|
||||||
|
| Some c \ { row = row, col = c }
|
||||||
|
| None \ { row = row, col = col }) # no match
|
||||||
|
| False \ (strLastIndexOf query (nth r lines ~ unwrapOr "")
|
||||||
|
| Some c \ { row = r, col = c }
|
||||||
|
| None \ findInLines (r - 1)));
|
||||||
|
findInLines (row - 1));
|
||||||
|
|
||||||
{
|
{
|
||||||
view = ctx \
|
view = ctx \
|
||||||
|
|
@ -320,17 +343,10 @@ textEditor = name \
|
||||||
updateSearchQuery (state.searchQuery & char) state;
|
updateSearchQuery (state.searchQuery & char) state;
|
||||||
|
|
||||||
endSearch = state \
|
endSearch = state \
|
||||||
# next = findNext state.searchQuery state.lines state.cursorRow state.cursorCol;
|
{ state = autoScroll state.{ mode = Normal }, emit = [] };
|
||||||
newState = autoScroll state.{
|
|
||||||
mode = Normal,
|
|
||||||
# cursorCol = next.col,
|
|
||||||
# cursorRow = next.row,
|
|
||||||
};
|
|
||||||
|
|
||||||
{ state = newState, emit = [] };
|
|
||||||
|
|
||||||
nextSearch = state \
|
nextSearch = state \
|
||||||
next = findNext state.searchQuery state.lines state.cursorRow state.cursorCol;
|
next = findNext state.searchQuery state.lines state.cursorRow (state.cursorCol + 1);
|
||||||
newState = autoScroll state.{
|
newState = autoScroll state.{
|
||||||
mode = Normal,
|
mode = Normal,
|
||||||
cursorCol = next.col,
|
cursorCol = next.col,
|
||||||
|
|
@ -339,6 +355,16 @@ textEditor = name \
|
||||||
|
|
||||||
{ state = newState, emit = [] };
|
{ state = newState, emit = [] };
|
||||||
|
|
||||||
|
prevSearch = state \
|
||||||
|
prev = findPrev state.searchQuery state.lines state.cursorRow state.cursorCol;
|
||||||
|
newState = autoScroll state.{
|
||||||
|
mode = Normal,
|
||||||
|
cursorCol = prev.col,
|
||||||
|
cursorRow = prev.row,
|
||||||
|
};
|
||||||
|
|
||||||
|
{ state = newState, emit = [] };
|
||||||
|
|
||||||
scrollHalfUp = state ctx \ (
|
scrollHalfUp = state ctx \ (
|
||||||
diff = floor ((ctx.h / 2) / lineH);
|
diff = floor ((ctx.h / 2) / lineH);
|
||||||
newRow = state.cursorRow - diff;
|
newRow = state.cursorRow - diff;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue