From f8f9e33032b7c1ed4cb46784d61d252979733572 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 31 Dec 2025 08:27:22 +0100 Subject: [PATCH] Directory fuzzy search and fix C: not opening --- src/backup/todo.txt | 5 ++--- src/text_editor/commands.cpp | 21 +++++++++++++-------- src/text_editor/text_editor.cpp | 2 +- src/text_editor/view.h | 1 + src/text_editor/window_command.cpp | 12 +++++++++--- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/backup/todo.txt b/src/backup/todo.txt index 85f4358..1b3a1cb 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -4,7 +4,8 @@ Use session 3: - Maybe status view, commit changes (like to buffer name or line) on enter? -- Search over buffer directory, close search, quick enter buffer? Not sure if line, more general purpose +- Upload sublime settings to git and also install script / update config script + How to go about search/replace, opening code and other considerations - We can use sed + find to search and replace, the automatic reopen should do the job @@ -48,8 +49,6 @@ Commands TODO: - Special: non editable, hotkeys don't work etc. 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 Some decl/function indexing in fuzzy format ISSUE? Fix jump scroll, the query ends up the last line on screen, kind of wacky diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index a63cbbe..b231640 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -23,7 +23,8 @@ String GetDir(Buffer *buffer) { if (buffer->is_dir) { return buffer->name; } else { - return ChopLastSlash(buffer->name); + String result = ChopLastSlash(buffer->name); + return result; } } @@ -443,7 +444,7 @@ bool IsOpenBoundary(char c) { return result; } -ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) { +ResolvedOpen ResolveOpen(Allocator alo, String path, String meta) { ResolvedOpen result = {}; path = Trim(path); @@ -473,7 +474,7 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) { // Web { if (StartsWith(path, "https://") || StartsWith(path, "http://")) { - result.path = Format(scratch, "%S %S", ConfigInternetBrowser, path); + result.path = Format(alo, "%S %S", ConfigInternetBrowser, path); result.kind = OpenKind_BackgroundExec; return result; } @@ -483,14 +484,17 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) { { if (StartsWith(path, "commit ")) { path = Skip(path, 7); - result.path = Format(scratch, "git --no-pager show %S", path); + result.path = Format(alo, "git --no-pager show %S", path); result.kind = OpenKind_Exec; return result; } } { - String p = NormalizePath(scratch, path); + String p = NormalizePath(alo, path); + if (p.len == 2 && IsAlphabetic(ToLowerCase(At(p, 0))) && At(p, 1) == ':') { + p = Format(alo, "%S/", p); + } String pstart = p; bool is_absolute = false; @@ -538,7 +542,7 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) { result.kind = OpenKind_Goto; return result; } else { - String workspace_path = Format(scratch, "%S/%S", WorkDir, path); + String workspace_path = Format(alo, "%S/%S", WorkDir, path); bool existing_buffer = GetBuffer(workspace_path, NULL); if (existing_buffer || FileExists(workspace_path)) { result.existing_buffer = existing_buffer; @@ -547,7 +551,7 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) { return result; } - String rel_path = Format(scratch, "%S/%S", GetMainDir(), path); + String rel_path = Format(alo, "%S/%S", GetMainDir(), path); existing_buffer = GetBuffer(rel_path, NULL); if (existing_buffer || FileExists(rel_path)) { result.existing_buffer = existing_buffer; @@ -578,9 +582,10 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) { } if (IsDir(o.path)) { View *view = WindowOpenBufferView(set.window, o.path); + SetFuzzy(view); Buffer *buffer = GetBuffer(view->active_buffer); ResetBuffer(buffer); - RawAppendf(buffer, "..\n"); + RawAppendf(buffer, "\n..\n"); for (FileIter it = IterateFiles(scratch, o.path); IsValid(it); Advance(&it)) { RawAppendf(buffer, "%S\n", it.filename); } diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 676a785..c71e7d5 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -561,7 +561,7 @@ void Update(Event event) { OnCommand(event); StatusWindowUpdate(); DebugWindowUpdate(); - CommandWindowUpdate(); + FuzzySearchViewUpdate(); SearchWindowUpdate(); UpdateProcesses(); CoUpdate(&event); diff --git a/src/text_editor/view.h b/src/text_editor/view.h index 31dbfea..4bf7600 100644 --- a/src/text_editor/view.h +++ b/src/text_editor/view.h @@ -21,6 +21,7 @@ struct View { struct { unsigned close : 1; unsigned special : 1; + unsigned fuzzy : 1; }; }; diff --git a/src/text_editor/window_command.cpp b/src/text_editor/window_command.cpp index 0c3fd38..1cf9a0c 100644 --- a/src/text_editor/window_command.cpp +++ b/src/text_editor/window_command.cpp @@ -41,10 +41,10 @@ Array FuzzySearchLines(Allocator allocator, Buffer *buffer, Int line_ return ratings; } -void CommandWindowUpdate() { +void FuzzySearchViewUpdate() { ProfileFunction(); BSet active = GetBSet(ActiveWindowID); - if (active.window->id == CommandWindowID) { + if (active.view->fuzzy) { Scratch scratch; String16 line_string = GetLineStringWithoutNL(active.buffer, 0); if (active.view->prev_search_line != line_string) { @@ -149,6 +149,7 @@ void Command_CommandWindowOpen() { BSet main = GetBSet(LastActiveLayoutWindowID); NextActiveWindowID = main.window->id; OpenCommand(active); + SelectRange(main.view, Range{}); } void CommandWindowLayout(Rect2I *rect, Int wx, Int wy) { @@ -161,6 +162,11 @@ void CommandWindowLayout(Rect2I *rect, Int wx, Int wy) { n->document_rect = n->total_rect = CutBottom(rect, barsize); } +void SetFuzzy(View *view) { + view->fuzzy = true; + AddHook(&view->hooks, "Open", "ctrl-q | enter", Command_CommandWindowOpen); +} + void CommandWindowInit() { Window *window = CreateWind(); CommandWindowID = window->id; @@ -168,6 +174,7 @@ void CommandWindowInit() { buffer->special = true; View *view = CreateView(buffer->id); view->special = true; + SetFuzzy(view); window->active_view = view->id; window->draw_line_numbers = false; window->draw_scrollbar = false; @@ -178,5 +185,4 @@ void CommandWindowInit() { window->sync_visibility_with_focus = true; window->lose_focus_on_escape = true; window->jump_history = false; - AddHook(&view->hooks, "Open", "ctrl-q | enter", Command_CommandWindowOpen); }