Find all: alt-enter, alt-f3

This commit is contained in:
Krzosa Karol
2025-12-27 11:29:40 +01:00
parent 6f9299e557
commit 9ae73e5c04
5 changed files with 86 additions and 13 deletions
+4 -1
View File
@@ -1,6 +1,10 @@
- What precise workflow do I need for me to be viable to use this?
- From a user (novice) point of view, how does it look like?
- Search
- alt + w: word search
- alt + c: case sensitive
- Open with seek string (open at pattern) filename:32 filename:/^Window$/
- build console window
- Show what process/coroutines are running and allow to kill (active process buffer?)
@@ -21,7 +25,6 @@ backlog
FEATURE Search whole words, case sensitive etc.
FEATURE Select all searched occurences
FEATURE commands for scrolling: center, cursor_at_bottom_of_screen, cursor_at_top
FEATURE Kill buffer command (it should be marked for deletion and deleted at the end of frame!)
FEATURE Some decl/function indexing in fuzzy format
ISSUE? Fix jump scroll, the query ends up the last line on screen, kind of wacky
FEATURE dump text editor state to file, restore state
+6 -10
View File
@@ -892,10 +892,9 @@ void Command_MakeFontSmaller() {
void Command_Open() {
BSet active = GetBSet(ActiveWindowID);
if (active.window->id == CommandWindowID) {
CommandWindowOpen(active);
} else {
Open(FetchLoadWord(active.view));
return;
}
Open(FetchLoadWord(active.view));
} RegisterCommand(Command_Open, "ctrl-q");
void Command_KillSelectedLines() {
@@ -1115,14 +1114,11 @@ void Command_InsertNewLineDown() {
} RegisterCommand(Command_InsertNewLineDown, "ctrl-enter");
void Command_NewLine() {
BSet active = GetBSet(ActiveWindowID);
if (active.window->id == CommandWindowID) {
CommandWindowOpen(active);
} else if (active.window->id == SearchWindowID) {
SearchWindowFindNext(true);
} else {
IdentedNewLine(active.view);
if (ActiveWindowID == CommandWindowID || ActiveWindowID == SearchWindowID) {
return;
}
BSet active = GetBSet(ActiveWindowID);
IdentedNewLine(active.view);
} RegisterCommand(Command_NewLine, "enter");
void Command_CreateCaretOnNextFind() {
+18
View File
@@ -159,6 +159,24 @@ Caret FindNext(Buffer *buffer, String16 needle, Caret caret) {
return result;
}
Array<Caret> FindAll(Allocator allocator, Buffer *buffer, String16 needle) {
Array<Caret> result = {allocator};
String16 string = GetString(buffer);
String16 start = string;
for (;;) {
Int index = 0;
if (Seek(string, needle, &index)) {
Int back = index + (Int)(string.data - start.data);
Int front = back + needle.len;
Add(&result, MakeCaret(front, back));
string = Skip(string, index + needle.len);
} else {
break;
}
}
return result;
}
void SelectRange(View *view, Caret caret) {
view->carets.len = 1;
view->carets[0] = caret;
+9 -1
View File
@@ -184,7 +184,7 @@ void EvalCommand(String16 command) {
EvalCommand(ToString(scratch, command));
}
void CommandWindowOpen(BSet active) {
void OpenCommand(BSet active) {
ProfileFunction();
Range range = active.view->carets[0].range;
String16 string = FetchLoadWord(active.view);
@@ -208,3 +208,11 @@ void CommandWindowOpen(BSet active) {
Open(string);
}
}
void Command_OpenCommand() {
if (ActiveWindowID != CommandWindowID) {
return;
}
BSet active = GetBSet(ActiveWindowID);
OpenCommand(active);
} RegisterCommand(Command_OpenCommand, "ctrl-q | enter");
+49 -1
View File
@@ -57,13 +57,61 @@ void SearchWindowFindNext(bool forward = true) {
main.window->search_bar_anchor = main.view->carets[0];
}
void Command_SearchNextInSearch() {
if (ActiveWindowID != SearchWindowID) {
return;
}
SearchWindowFindNext(true);
} RegisterCommand(Command_SearchNextInSearch, "enter");
void Command_SearchPrevInSearch() {
if (ActiveWindowID != SearchWindowID) {
return;
}
SearchWindowFindNext(false);
} RegisterCommand(Command_SearchPrevInSearch, "shift-enter");
void Command_SearchNext() {
SearchWindowFindNext(true);
} RegisterCommand(Command_SearchNext, "f3");
void Command_SearchPrev() {
SearchWindowFindNext(false);
} RegisterCommand(Command_SearchPrev, "shift-f3 | shift-enter");
} RegisterCommand(Command_SearchPrev, "shift-f3");
void SearchAll() {
Scratch scratch;
BSet main = GetBSet(LastActiveLayoutWindowID);
BSet set = GetBSet(SearchWindowID);
String16 needle = GetString(set.buffer, GetRange(set.buffer));
Array<Caret> all = FindAll(scratch, main.buffer, needle);
if (all.len > 0) {
main.view->carets.len = 0;
For (all) {
Add(&main.view->carets, it);
}
MergeCarets(main.buffer, &main.view->carets);
}
}
void Command_SearchAll() {
SearchAll();
BSet set = GetBSet(SearchWindowID);
set.window->visible = false;
ActiveWindowID = LastActiveLayoutWindowID;
} RegisterCommand(Command_SearchAll, "alt-f3");
void Command_SearchAllInSearch() {
if (ActiveWindowID != SearchWindowID) {
return;
}
SearchAll();
BSet set = GetBSet(SearchWindowID);
set.window->visible = false;
ActiveWindowID = LastActiveLayoutWindowID;
} RegisterCommand(Command_SearchAllInSearch, "alt-enter");
void SearchWindowUpdate() {
BSet active = GetBSet(ActiveWindowID);