Implement new search window

This commit is contained in:
krzosa
2025-12-23 08:52:42 +01:00
parent edc941bf53
commit c67db4e495
8 changed files with 55 additions and 11 deletions

View File

@@ -1,7 +1,9 @@
- 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?
- Show what process/coroutines are running and allow to kill (active process buffer?)
- ctrl + p like in VSCode (without special buffers)
- I THINK WE NEED A SPECIAL VIEW, this is too slow
- Move to the top so that it can be progressively expanded using coroutines by appending at the end
- Maybe 2 windows?
- Guide on the first page for new users with links to configs, tutorials

View File

@@ -18,6 +18,7 @@ struct HistoryEntry {
struct Buffer {
BufferID id;
String name;
Int begin_frame_change_id;
Int change_id;
Int user_change_id;
Int file_mod_time;

View File

@@ -1063,6 +1063,8 @@ 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);
}
@@ -1108,7 +1110,6 @@ void Command_ClearCarets() {
active.view->carets.len = 1;
active.view->carets[0] = MakeCaret(GetFront(active.view->carets[0]));
// @todo: move to hook post command???
if (active.window->lose_focus_on_escape && active.window->id == ActiveWindowID) {
if (active.window->layout) {
//
@@ -1116,4 +1117,13 @@ void Command_ClearCarets() {
ActiveWindowID = LastActiveLayoutWindowID;
}
}
For (Windows) {
if (it->lose_visibility_on_escape && it->visible) {
if (ActiveWindowID == it->id) {
ActiveWindowID = LastActiveLayoutWindowID;
}
it->visible = false;
}
}
} RegisterCommand(Command_ClearCarets, "escape");

View File

@@ -27,7 +27,7 @@ BufferID DebugBufferID;
WindowID CommandWindowID;
WindowID StatusBarWindowID;
WindowID SearchBarWindowID;
WindowID SearchWindowID;
ViewID SearchViewID;
BufferID SearchBufferID;

View File

@@ -388,7 +388,6 @@ void OnCommand(Event event) {
BSet main = GetBSet(LastActiveLayoutWindowID);
BSet active = GetBSet(ActiveWindowID);
Int buffer_change_id = active.buffer->change_id;
For (CommandFunctions) {
if (it.trigger && MatchEvent(it.trigger, &event)) {
@@ -514,12 +513,15 @@ void Update(Event event) {
view->update_scroll = true;
}
OnCommand(event);
StatusWindowUpdate();
DebugWindowUpdate();
CommandWindowUpdate();
SearchWindowUpdate();
UpdateProcesses();
CoUpdate(&event);
For (Buffers) it->begin_frame_change_id = it->change_id; // after last place we modify
{
ProfileScope(WindowEndOfFrameVisibilityAndLastActive);

View File

@@ -15,7 +15,7 @@ struct Window {
double mouse_scroller_offset;
int z;
double weight;
Int status_bar_last_buffer_change_id;
Caret search_bar_anchor;
Array<GotoCrumb> goto_history;
Array<GotoCrumb> goto_redo;
@@ -33,6 +33,7 @@ struct Window {
bool close : 1;
bool sync_visibility_with_focus : 1;
bool lose_focus_on_escape : 1;
bool lose_visibility_on_escape : 1;
bool jump_history : 1;
bool eval_command : 1;
};

View File

@@ -1,6 +1,6 @@
void SearchWindowInit() {
Window *window = CreateWind();
SearchBarWindowID = window->id;
SearchWindowID = window->id;
Buffer *buffer = CreateBuffer(SysAllocator, "search_bar");
buffer->special = true;
SearchBufferID = buffer->id;
@@ -14,11 +14,11 @@ void SearchWindowInit() {
window->draw_line_highlight = false;
window->layout = false;
window->visible = false;
window->lose_focus_on_escape = true;
window->lose_visibility_on_escape = true;
}
void SearchWindowLayout(Rect2I *rect, Int wx, Int wy) {
Window *n = GetWindow(SearchBarWindowID);
Window *n = GetWindow(SearchWindowID);
Rect2I copy_rect = *rect;
if (!n->visible) {
rect = &copy_rect;
@@ -28,6 +28,35 @@ void SearchWindowLayout(Rect2I *rect, Int wx, Int wy) {
}
void Command_Search() {
Window *window = GetWindow(SearchBarWindowID);
window->visible = !window->visible;
BSet set = GetBSet(SearchWindowID);
set.window->visible = true;
ActiveWindowID = SearchWindowID;
SelectEntireBuffer(set.view);
} RegisterCommand(Command_Search, "ctrl-f");
void SearchWindowFindNext(bool forward = true) {
BSet main = GetBSet(LastActiveLayoutWindowID);
BSet set = GetBSet(SearchWindowID);
String16 seek = GetString(set.buffer, GetRange(set.buffer));
Find(main.view, seek, forward);
main.window->search_bar_anchor = main.view->carets[0];
}
void Command_SearchNext() {
SearchWindowFindNext(true);
} RegisterCommand(Command_SearchNext, "f3");
void Command_SearchPrev() {
SearchWindowFindNext(false);
} RegisterCommand(Command_SearchPrev, "shift-f3 | shift-enter");
void SearchWindowUpdate() {
BSet active = GetBSet(ActiveWindowID);
if (active.window->id == SearchWindowID && active.buffer->begin_frame_change_id != active.buffer->change_id) {
BSet main = GetBSet(LastActiveLayoutWindowID);
BSet set = GetBSet(SearchWindowID);
main.view->carets[0] = main.window->search_bar_anchor;
String16 seek = GetString(set.buffer, GetRange(set.buffer));
Find(main.view, seek, true);
}
}

View File

@@ -42,7 +42,7 @@ void StatusWindowUpdate() {
// Parse the title and line
if (title.window->id == ActiveWindowID) {
if (title.buffer->change_id == title.window->status_bar_last_buffer_change_id) {
if (title.buffer->change_id == title.buffer->begin_frame_change_id) {
return;
}
String16 buffer_name = GetString(title.buffer, replace_range);
@@ -63,7 +63,6 @@ void StatusWindowUpdate() {
if (GetFront(caret) != buffer_pos) {
caret = MakeCaret(buffer_pos);
}
title.window->status_bar_last_buffer_change_id = title.buffer->change_id;
return;
}