Fix bug in coroutine of SearchProject and use selected string as seed for search

This commit is contained in:
Krzosa Karol
2026-01-05 10:14:35 +01:00
parent 9073909cfc
commit 40b15ec7aa

View File

@@ -153,8 +153,15 @@ struct SearchProjectParams {
void Coro_SearchProject(mco_coro *co) { void Coro_SearchProject(mco_coro *co) {
SearchProjectParams *param = (SearchProjectParams *)CoCurr->user_ctx; SearchProjectParams *param = (SearchProjectParams *)CoCurr->user_ctx;
Array<BufferID> buffers = {CoCurr->arena};
For (Buffers) { 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; continue;
} }
@@ -253,6 +260,11 @@ void FuzzySearchViewUpdate() {
void CMD_SearchProject() { void CMD_SearchProject() {
BSet main = GetBSet(PrimaryWindowID); 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; NextActiveWindowID = main.window->id;
Buffer *search_project_buffer = GetBuffer(SearchProjectBufferID); Buffer *search_project_buffer = GetBuffer(SearchProjectBufferID);
View *view = WindowOpenBufferView(main.window, search_project_buffer->name); View *view = WindowOpenBufferView(main.window, search_project_buffer->name);
@@ -260,6 +272,10 @@ void CMD_SearchProject() {
view->kind = ViewKind_ActiveSearch; view->kind = ViewKind_ActiveSearch;
AddHook(&view->hooks, "Open", "ctrl-q | enter", CMD_CommandWindowOpen); AddHook(&view->hooks, "Open", "ctrl-q | enter", CMD_CommandWindowOpen);
SelectRange(view, GetLineRangeWithoutNL(search_project_buffer, 0)); 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"); } RegisterCommand(CMD_SearchProject, "ctrl-shift-f", "Interactive search over the entire project in a new buffer view");
void SetFuzzy(View *view) { void SetFuzzy(View *view) {