From d5f903eaa244f99b42a17bbfe17891e32230d565 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sat, 10 Aug 2024 08:46:40 +0200 Subject: [PATCH] Reword ListBuffers --- src/basic/string16.cpp | 2 +- src/text_editor/lua_api.cpp | 14 +++++++++----- src/text_editor/management.cpp | 5 +++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/basic/string16.cpp b/src/basic/string16.cpp index e24728d..3c5b005 100644 --- a/src/basic/string16.cpp +++ b/src/basic/string16.cpp @@ -30,7 +30,7 @@ bool IsWord(wchar_t w) { } bool IsLoadWord(wchar_t w) { - bool result = w == '/' || w == '\\' || w == ':' || w == '*' || w == '_' || w == '.' || w == '-'; + bool result = w == '/' || w == '\\' || w == ':' || w == '+' || w == '_' || w == '.' || w == '-'; if (!result) { result = !(IsSymbol(w) || IsWhitespace(w)); } diff --git a/src/text_editor/lua_api.cpp b/src/text_editor/lua_api.cpp index 82a1a77..c8ec955 100644 --- a/src/text_editor/lua_api.cpp +++ b/src/text_editor/lua_api.cpp @@ -145,22 +145,26 @@ int Lua_Print(lua_State *L) { } int Lua_ListBuffers(lua_State *L) { - Window *window = GetWindow(ActiveWindow); + Window *window = GetWindow(GetLastActiveWindow()); View *view = GetView(window->active_view); + Buffer *buffer = GetBuffer(view->active_buffer); + CheckpointBeforeGoto(window->id); Scratch scratch; Array strings = {scratch}; For(Buffers) { - if (StartsWith(it.name, "+titlebar")) continue; String string = Format(scratch, "%.*s", FmtString(it.name)); Add(&strings, string); } String result = Merge(scratch, strings, "\n"); String16 string16 = ToString16(scratch, result); - Command_SelectEntireBuffer(view); - Command_Replace(view, string16); - Command_SelectRangeOneCursor(view, {}); + String buffer_name = GetUniqueBufferName(scratch, GetDir(buffer), "+list_buffers-"); + View *new_view = WindowOpenBufferView(window, buffer_name); + + Command_SelectEntireBuffer(new_view); + Command_Replace(new_view, string16); + Command_SelectRangeOneCursor(new_view, {}); return 0; } diff --git a/src/text_editor/management.cpp b/src/text_editor/management.cpp index ae69275..e058b89 100644 --- a/src/text_editor/management.cpp +++ b/src/text_editor/management.cpp @@ -196,6 +196,11 @@ String GetCurrentBufferName() { return buffer->name; } +String GetDir(Buffer *buffer) { + String name = buffer->is_directory ? buffer->name : ChopLastSlash(buffer->name); + return name; +} + String GetCurrentBufferDir() { Window *window = GetCurrentWindow(); View *view = GetView(window->active_view);