Directory fuzzy search and fix C: not opening

This commit is contained in:
Krzosa Karol
2025-12-31 08:27:22 +01:00
parent beaf072740
commit f8f9e33032
5 changed files with 26 additions and 15 deletions

View File

@@ -4,7 +4,8 @@
Use session 3: Use session 3:
- Maybe status view, commit changes (like to buffer name or line) on enter? - 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 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 - 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. - Special: non editable, hotkeys don't work etc.
backlog 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 commands for scrolling: center, cursor_at_bottom_of_screen, cursor_at_top
FEATURE Some decl/function indexing in fuzzy format FEATURE Some decl/function indexing in fuzzy format
ISSUE? Fix jump scroll, the query ends up the last line on screen, kind of wacky ISSUE? Fix jump scroll, the query ends up the last line on screen, kind of wacky

View File

@@ -23,7 +23,8 @@ String GetDir(Buffer *buffer) {
if (buffer->is_dir) { if (buffer->is_dir) {
return buffer->name; return buffer->name;
} else { } else {
return ChopLastSlash(buffer->name); String result = ChopLastSlash(buffer->name);
return result;
} }
} }
@@ -443,7 +444,7 @@ bool IsOpenBoundary(char c) {
return result; return result;
} }
ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) { ResolvedOpen ResolveOpen(Allocator alo, String path, String meta) {
ResolvedOpen result = {}; ResolvedOpen result = {};
path = Trim(path); path = Trim(path);
@@ -473,7 +474,7 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) {
// Web // Web
{ {
if (StartsWith(path, "https://") || StartsWith(path, "http://")) { 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; result.kind = OpenKind_BackgroundExec;
return result; return result;
} }
@@ -483,14 +484,17 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) {
{ {
if (StartsWith(path, "commit ")) { if (StartsWith(path, "commit ")) {
path = Skip(path, 7); 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; result.kind = OpenKind_Exec;
return result; 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; String pstart = p;
bool is_absolute = false; bool is_absolute = false;
@@ -538,7 +542,7 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) {
result.kind = OpenKind_Goto; result.kind = OpenKind_Goto;
return result; return result;
} else { } 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); bool existing_buffer = GetBuffer(workspace_path, NULL);
if (existing_buffer || FileExists(workspace_path)) { if (existing_buffer || FileExists(workspace_path)) {
result.existing_buffer = existing_buffer; result.existing_buffer = existing_buffer;
@@ -547,7 +551,7 @@ ResolvedOpen ResolveOpen(Allocator scratch, String path, String meta) {
return result; 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); existing_buffer = GetBuffer(rel_path, NULL);
if (existing_buffer || FileExists(rel_path)) { if (existing_buffer || FileExists(rel_path)) {
result.existing_buffer = existing_buffer; 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)) { if (IsDir(o.path)) {
View *view = WindowOpenBufferView(set.window, o.path); View *view = WindowOpenBufferView(set.window, o.path);
SetFuzzy(view);
Buffer *buffer = GetBuffer(view->active_buffer); Buffer *buffer = GetBuffer(view->active_buffer);
ResetBuffer(buffer); ResetBuffer(buffer);
RawAppendf(buffer, "..\n"); RawAppendf(buffer, "\n..\n");
for (FileIter it = IterateFiles(scratch, o.path); IsValid(it); Advance(&it)) { for (FileIter it = IterateFiles(scratch, o.path); IsValid(it); Advance(&it)) {
RawAppendf(buffer, "%S\n", it.filename); RawAppendf(buffer, "%S\n", it.filename);
} }

View File

@@ -561,7 +561,7 @@ void Update(Event event) {
OnCommand(event); OnCommand(event);
StatusWindowUpdate(); StatusWindowUpdate();
DebugWindowUpdate(); DebugWindowUpdate();
CommandWindowUpdate(); FuzzySearchViewUpdate();
SearchWindowUpdate(); SearchWindowUpdate();
UpdateProcesses(); UpdateProcesses();
CoUpdate(&event); CoUpdate(&event);

View File

@@ -21,6 +21,7 @@ struct View {
struct { struct {
unsigned close : 1; unsigned close : 1;
unsigned special : 1; unsigned special : 1;
unsigned fuzzy : 1;
}; };
}; };

View File

@@ -41,10 +41,10 @@ Array<FuzzyPair> FuzzySearchLines(Allocator allocator, Buffer *buffer, Int line_
return ratings; return ratings;
} }
void CommandWindowUpdate() { void FuzzySearchViewUpdate() {
ProfileFunction(); ProfileFunction();
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);
if (active.window->id == CommandWindowID) { if (active.view->fuzzy) {
Scratch scratch; Scratch scratch;
String16 line_string = GetLineStringWithoutNL(active.buffer, 0); String16 line_string = GetLineStringWithoutNL(active.buffer, 0);
if (active.view->prev_search_line != line_string) { if (active.view->prev_search_line != line_string) {
@@ -149,6 +149,7 @@ void Command_CommandWindowOpen() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
NextActiveWindowID = main.window->id; NextActiveWindowID = main.window->id;
OpenCommand(active); OpenCommand(active);
SelectRange(main.view, Range{});
} }
void CommandWindowLayout(Rect2I *rect, Int wx, Int wy) { 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); 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() { void CommandWindowInit() {
Window *window = CreateWind(); Window *window = CreateWind();
CommandWindowID = window->id; CommandWindowID = window->id;
@@ -168,6 +174,7 @@ void CommandWindowInit() {
buffer->special = true; buffer->special = true;
View *view = CreateView(buffer->id); View *view = CreateView(buffer->id);
view->special = true; view->special = true;
SetFuzzy(view);
window->active_view = view->id; window->active_view = view->id;
window->draw_line_numbers = false; window->draw_line_numbers = false;
window->draw_scrollbar = false; window->draw_scrollbar = false;
@@ -178,5 +185,4 @@ void CommandWindowInit() {
window->sync_visibility_with_focus = true; window->sync_visibility_with_focus = true;
window->lose_focus_on_escape = true; window->lose_focus_on_escape = true;
window->jump_history = false; window->jump_history = false;
AddHook(&view->hooks, "Open", "ctrl-q | enter", Command_CommandWindowOpen);
} }