From 0c7a424f5e66fdc68be2ece99da11d1d304a9ec5 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Mon, 12 May 2025 17:40:19 +0200 Subject: [PATCH] ListCode with || --- src/text_editor/commands.cpp | 13 +++++++++---- src/text_editor/commands_bindings.cpp | 26 +++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 766fc41..76f689c 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -1055,21 +1055,26 @@ void ListFilesRecursive(Buffer *buffer, String dir) { if (!good) { continue; } - RawAppendf(buffer, "%-100.*s %.*s\n", FmtString(it.absolute_path), FmtString(it.filename)); + RawAppendf(buffer, "%-80.*s || %.*s\n", FmtString(it.filename), FmtString(it.absolute_path)); } } } -void Command_ListCode(void) { +void Command_ListCode(String dir = WorkDir) { BSet main = GetActiveMainSet(); JumpGarbageBuffer(&main); - ListFilesRecursive(main.buffer, WorkDir); + ListFilesRecursive(main.buffer, dir); main.view->fuzzy_search = true; Command_SelectRangeOneCursor(main.view, GetEndAsRange(main.buffer)); } int Lua_ListCode(lua_State *L) { - Command_ListCode(); + String string = lua_tostring(L, 1); + lua_pop(L, 1); + if (string.len == 0) { + string = WorkDir; + } + Command_ListCode(string); return 0; } diff --git a/src/text_editor/commands_bindings.cpp b/src/text_editor/commands_bindings.cpp index f7b3405..3235592 100644 --- a/src/text_editor/commands_bindings.cpp +++ b/src/text_editor/commands_bindings.cpp @@ -615,10 +615,30 @@ void OnCommand(Event event) { if (CtrlShiftPress(SDLK_Q)) { Command_Open(FetchLoadWord(), "exec"); } else if (CtrlPress(SDLK_Q)) { - Command_Open(FetchLoadWord()); if (active.view->fuzzy_search) { - Range rng = GetLineRangeWithoutNL(active.buffer, active.buffer->line_starts.len - 1); - GetLast(active.window->goto_history)->caret = MakeCaret(rng.max, rng.min); + bool success = false; + Range range = active.view->carets[0].range; + if (GetSize(range) == 0) { + Int line = PosToLine(active.buffer, range.min); + String16 string = GetLineStringWithoutNL(active.buffer, line); + Int idx = 0; + if (Seek(string, u"||", &idx)) { + string = Skip(string, idx + 3); + Command_Open(string); + success = true; + } + } + + if (!success) { + Command_Open(FetchLoadWord()); + } + + { + Range rng = GetLineRangeWithoutNL(active.buffer, active.buffer->line_starts.len - 1); + GetLast(active.window->goto_history)->caret = MakeCaret(rng.max, rng.min); + } + } else { + Command_Open(FetchLoadWord()); } }