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
|
||||
|
||||
# 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 \
|
||||
# defaults = {};
|
||||
# c = { ...defaults, ...config };
|
||||
|
|
@ -136,7 +144,6 @@ textEditor = name \
|
|||
{ state = state, emit = [rebindAt [buffersKey, name] content] };
|
||||
|
||||
apply = state \
|
||||
# content = name & " = " & (join "\n" state.lines) & ";";
|
||||
content = (join "\n" state.lines);
|
||||
result = eval! content;
|
||||
_ = debug! "apply" [content, result];
|
||||
|
|
@ -243,7 +250,7 @@ textEditor = name \
|
|||
{ state = newState, emit = [] };
|
||||
|
||||
findNext = query lines row col \
|
||||
rest = strIndexOf query (nth row lines ~ unwrapOr "") (col + 1);
|
||||
rest = strIndexOf query (nth row lines ~ unwrapOr "") col;
|
||||
rest
|
||||
| Some c \ { row = row, col = c }
|
||||
| None \ (
|
||||
|
|
@ -259,7 +266,23 @@ textEditor = name \
|
|||
| None \ findInLines (r + 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 \
|
||||
|
|
@ -320,17 +343,10 @@ textEditor = name \
|
|||
updateSearchQuery (state.searchQuery & char) state;
|
||||
|
||||
endSearch = state \
|
||||
# next = findNext state.searchQuery state.lines state.cursorRow state.cursorCol;
|
||||
newState = autoScroll state.{
|
||||
mode = Normal,
|
||||
# cursorCol = next.col,
|
||||
# cursorRow = next.row,
|
||||
};
|
||||
|
||||
{ state = newState, emit = [] };
|
||||
{ state = autoScroll state.{ mode = Normal }, emit = [] };
|
||||
|
||||
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.{
|
||||
mode = Normal,
|
||||
cursorCol = next.col,
|
||||
|
|
@ -339,6 +355,16 @@ textEditor = name \
|
|||
|
||||
{ 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 \ (
|
||||
diff = floor ((ctx.h / 2) / lineH);
|
||||
newRow = state.cursorRow - diff;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue