From 40b15ec7aae9f0310be9fbb14726119b35e1f044 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Mon, 5 Jan 2026 10:14:35 +0100 Subject: [PATCH] Fix bug in coroutine of SearchProject and use selected string as seed for search --- src/text_editor/window_command.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/text_editor/window_command.cpp b/src/text_editor/window_command.cpp index 102c526..cf367f1 100644 --- a/src/text_editor/window_command.cpp +++ b/src/text_editor/window_command.cpp @@ -153,8 +153,15 @@ struct SearchProjectParams { void Coro_SearchProject(mco_coro *co) { SearchProjectParams *param = (SearchProjectParams *)CoCurr->user_ctx; + + Array buffers = {CoCurr->arena}; For (Buffers) { - if (it->special || it->is_dir || it->temp || it->dont_try_to_save_in_bulk_ops) { + Add(&buffers, it->id); + } + + ForItem (id, buffers) { + Buffer *it = GetBuffer(id, NULL); + if (it == NULL || it->special || it->is_dir || it->temp || it->dont_try_to_save_in_bulk_ops) { continue; } @@ -253,6 +260,11 @@ void FuzzySearchViewUpdate() { void CMD_SearchProject() { BSet main = GetBSet(PrimaryWindowID); + String16 string = {}; + if (main.view->carets.len == 1 && GetSize(main.view->carets[0]) > 0) { + string = GetString(main.buffer, main.view->carets[0].range); + } + NextActiveWindowID = main.window->id; Buffer *search_project_buffer = GetBuffer(SearchProjectBufferID); View *view = WindowOpenBufferView(main.window, search_project_buffer->name); @@ -260,6 +272,10 @@ void CMD_SearchProject() { view->kind = ViewKind_ActiveSearch; AddHook(&view->hooks, "Open", "ctrl-q | enter", CMD_CommandWindowOpen); SelectRange(view, GetLineRangeWithoutNL(search_project_buffer, 0)); + if (string.len) { + Replace(view, string); + SelectEntireBuffer(view); + } } RegisterCommand(CMD_SearchProject, "ctrl-shift-f", "Interactive search over the entire project in a new buffer view"); void SetFuzzy(View *view) {