From 725cdde0075db88e1fb665d15edaba750065be2f Mon Sep 17 00:00:00 2001 From: krzosa Date: Sun, 21 Dec 2025 22:26:15 +0100 Subject: [PATCH] Rename to Config, Fix slowness of ShowCommands and improve quality --- src/backup/todo.txt | 1 - src/test/tests.cpp | 2 +- src/text_editor/buffer.cpp | 2 +- src/text_editor/commands.cpp | 10 +++++----- src/text_editor/{parser.cpp => config.cpp} | 4 ++-- src/text_editor/globals.cpp | 19 ++++++++++--------- src/text_editor/text_editor.cpp | 11 +++++++---- src/text_editor/view.cpp | 10 +++++----- src/text_editor/window.cpp | 8 ++++---- src/text_editor/window_command.cpp | 12 +++++++++++- 10 files changed, 46 insertions(+), 33 deletions(-) rename src/text_editor/{parser.cpp => config.cpp} (98%) diff --git a/src/backup/todo.txt b/src/backup/todo.txt index dc3ac60..c9fe551 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -1,7 +1,6 @@ - What precise workflow do I need for me to be viable to use this? - From a user (novice) point of view, how does it look like? -- Remove LUA and replace with keybindings, config, commands - "DO YOU REALLY WANT TO QUIT?" popup - open all in the folder and ctrl + p like in VSCode (without special buffers) - Guide on the first page for new users with links to configs, tutorials diff --git a/src/test/tests.cpp b/src/test/tests.cpp index 9976725..14c7509 100644 --- a/src/test/tests.cpp +++ b/src/test/tests.cpp @@ -150,7 +150,7 @@ void Test(mco_coro *co) { } void InitTests() { - StyleWaitForEvents = false; + ConfigWaitForEvents = false; TestDir = Format(TestArena, "%S/test_env", GetExeDir(TestArena)); CoAdd(Test); } diff --git a/src/text_editor/buffer.cpp b/src/text_editor/buffer.cpp index 5dac7c5..0177ae7 100644 --- a/src/text_editor/buffer.cpp +++ b/src/text_editor/buffer.cpp @@ -1005,7 +1005,7 @@ API void UndoEdit(Buffer *buffer, Array *carets) { if (buffer->undo_stack.len > 0) { HistoryEntry *next = GetLast(buffer->undo_stack); - if (entry.time - next->time <= StyleUndoMergeTimeout) { + if (entry.time - next->time <= ConfigUndoMergeTimeout) { UndoEdit(buffer, carets); } } diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index a4986e9..84f0580 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -718,14 +718,14 @@ void Command_Undo() { } RegisterCommand(Command_Undo, "ctrl-z"); void Command_MakeFontLarger() { - StyleFontSize += 1; - ReloadFont(StyleFont, (U32)StyleFontSize); + ConfigFontSize += 1; + ReloadFont(ConfigFont, (U32)ConfigFontSize); } RegisterCommand(Command_MakeFontLarger, "ctrl-equals"); void Command_MakeFontSmaller() { - if (StyleFontSize > 4) { - StyleFontSize -= 1; - ReloadFont(StyleFont, (U32)StyleFontSize); + if (ConfigFontSize > 4) { + ConfigFontSize -= 1; + ReloadFont(ConfigFont, (U32)ConfigFontSize); } } RegisterCommand(Command_MakeFontSmaller, "ctrl-minus"); diff --git a/src/text_editor/parser.cpp b/src/text_editor/config.cpp similarity index 98% rename from src/text_editor/parser.cpp rename to src/text_editor/config.cpp index 94b2573..7e90476 100644 --- a/src/text_editor/parser.cpp +++ b/src/text_editor/config.cpp @@ -56,7 +56,7 @@ String AsString(Lexer *lex) { } void EatWhitespace(Lexer *lex) { - while (IsWhitespace(At(lex))) { + while (At(lex) != '\n' && IsWhitespace(At(lex))) { Advance(lex); } } @@ -242,4 +242,4 @@ void TestParser() { } -} RegisterFunction(&TestFunctions, TestParser); \ No newline at end of file +} RegisterFunction(&TestFunctions, TestParser); diff --git a/src/text_editor/globals.cpp b/src/text_editor/globals.cpp index ee95823..113e88f 100644 --- a/src/text_editor/globals.cpp +++ b/src/text_editor/globals.cpp @@ -74,6 +74,7 @@ String Intern(InternTable *table, String string) { // optimize worst offenders (like event text) InternTable GlobalInternTable; +Function *LastExecutedCommand; Array CommandFunctions; Array TestFunctions; Array Variables; @@ -143,13 +144,13 @@ RegisterVariable(Color, ColorTitleBarActiveBackground, {0xfe, 0xfe, 0xfe, 0xfe}) RegisterVariable(Color, ColorTitleBarSelection, GruvboxLight3); RegisterVariable(Color, ColorResizerBackground, GruvboxLight0Hard); RegisterVariable(Color, ColorResizerOutline, GruvboxLight3); -RegisterVariable(Int, StyleWaitForEvents, 1); -RegisterVariable(Int, StyleDrawLineNumbers, 1); -RegisterVariable(Int, StyleDrawScrollbar, 1); -RegisterVariable(Int, StyleIndentSize, 4); -RegisterVariable(Int, StyleFontSize, 15); -RegisterVariable(Int, StyleFontFilter, 0); -RegisterVariable(String, StyleFont, "/home/krz/text_editor/package/CascadiaMono.ttf"); -RegisterVariable(String, StyleVCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat"); -RegisterVariable(Float, StyleUndoMergeTimeout, 0.3); +RegisterVariable(Int, ConfigWaitForEvents, 1); +RegisterVariable(Int, ConfigDrawLineNumbers, 1); +RegisterVariable(Int, ConfigDrawScrollbar, 1); +RegisterVariable(Int, ConfigIndentSize, 4); +RegisterVariable(Int, ConfigFontSize, 15); +RegisterVariable(Int, ConfigFontFilter, 0); +RegisterVariable(String, ConfigFont, "/home/krz/text_editor/package/CascadiaMono.ttf"); +RegisterVariable(String, ConfigVCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat"); +RegisterVariable(Float, ConfigUndoMergeTimeout, 0.3); RegisterVariable(String, ConfigInternetBrowser, "firefox"); diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 3754f83..22eaf46 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -33,7 +33,7 @@ #include "process.cpp" #include "event.cpp" -#include "parser.cpp" +#include "config.cpp" #include "commands.cpp" #include "commands_clipboard.cpp" @@ -392,7 +392,10 @@ void OnCommand(Event event) { For (CommandFunctions) { if (it.trigger && MatchEvent(it.trigger, &event)) { + double start = GetTimeSeconds(); it.function(); + ReportConsolef("%S: %f", it.name, GetTimeSeconds() - start); + LastExecutedCommand = it.function; } } @@ -520,7 +523,7 @@ void Windows_SetupVCVarsall(mco_coro *co) { Scratch scratch; String working_dir = WorkDir; String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-"); - String cmd = Format(scratch, "\"%S\" && set", StyleVCVarsall); + String cmd = Format(scratch, "\"%S\" && set", ConfigVCVarsall); view = ExecHidden(buffer_name, cmd, working_dir); } for (;;) { @@ -568,7 +571,7 @@ void MainLoop() { Update(it); } - WaitForEvents = StyleWaitForEvents; + WaitForEvents = ConfigWaitForEvents; if (IsDocumentSelectionValid() || IsScrollbarSelectionValid() || ActiveProcesses.len) { WaitForEvents = false; } @@ -710,7 +713,7 @@ int main(int argc, char **argv) InitBuffers(); InitRender(); - ReloadFont(StyleFont, (U32)StyleFontSize); + ReloadFont(ConfigFont, (U32)ConfigFontSize); InitWindows(); InitOS(ReportWarningf); diff --git a/src/text_editor/view.cpp b/src/text_editor/view.cpp index 42726ec..7cfb6d7 100644 --- a/src/text_editor/view.cpp +++ b/src/text_editor/view.cpp @@ -403,9 +403,9 @@ void Delete(View *view, int direction, bool ctrl = false) { Range indent_range = GetIndentRangeAtPos(buffer, it.range.min); if (ctrl == false && it.range.min > indent_range.min && it.range.max <= indent_range.max) { Int offset = it.range.min - indent_range.min; - Int to_delete = (offset % (StyleIndentSize)); - if (to_delete == 0) to_delete = StyleIndentSize; - to_delete = Clamp(to_delete, (Int)1, StyleIndentSize); + Int to_delete = (offset % (ConfigIndentSize)); + if (to_delete == 0) to_delete = ConfigIndentSize; + to_delete = Clamp(to_delete, (Int)1, ConfigIndentSize); for (Int i = 0; i < to_delete; i += 1) { it = MoveCaret(buffer, it, direction, false, SHIFT_PRESS); } @@ -472,12 +472,12 @@ void IndentSelectedLines(View *view, bool shift = false) { Range pos_range_of_line = GetLineRange(buffer, i); if (!shift) { - String16 whitespace_string = {u" ", StyleIndentSize}; + String16 whitespace_string = {u" ", ConfigIndentSize}; AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, whitespace_string); } else { String16 string = GetString(buffer, pos_range_of_line); Int whitespace_len = 0; - for (Int i = 0; i < StyleIndentSize && i < string.len && string.data[i] == ' '; i += 1) { + for (Int i = 0; i < ConfigIndentSize && i < string.len && string.data[i] == ' '; i += 1) { whitespace_len += 1; } diff --git a/src/text_editor/window.cpp b/src/text_editor/window.cpp index 99865fd..c96166f 100644 --- a/src/text_editor/window.cpp +++ b/src/text_editor/window.cpp @@ -8,8 +8,8 @@ Window *CreateWind() { w->font = &PrimaryFont; w->visible = true; w->layout = true; - w->draw_scrollbar = StyleDrawScrollbar; - w->draw_line_numbers = StyleDrawLineNumbers; + w->draw_scrollbar = ConfigDrawScrollbar; + w->draw_line_numbers = ConfigDrawLineNumbers; w->draw_line_highlight = true; w->jump_history = true; w->id = AllocWindowID(w); @@ -257,7 +257,7 @@ void GotoBackward(Window *window) { if (window->goto_history.len) { GotoCrumb *next = GetLast(window->goto_history); - if (c.time - next->time <= StyleUndoMergeTimeout) { + if (c.time - next->time <= ConfigUndoMergeTimeout) { GotoBackward(window); } } @@ -277,7 +277,7 @@ void GotoForward(Window *window) { if (window->goto_redo.len) { GotoCrumb *next = GetLast(window->goto_redo); - if (c.time - next->time <= StyleUndoMergeTimeout) { + if (c.time - next->time <= ConfigUndoMergeTimeout) { GotoForward(window); } } diff --git a/src/text_editor/window_command.cpp b/src/text_editor/window_command.cpp index e0fc7d5..f8c2161 100644 --- a/src/text_editor/window_command.cpp +++ b/src/text_editor/window_command.cpp @@ -55,19 +55,29 @@ void CommandWindowUpdate() { } void Command_ShowCommands() { + if (ActiveWindowID == CommandBarWindowID && LastExecutedCommand == Command_ShowCommands) { + ActiveWindowID = LastActiveLayoutWindowID; + return; + } + BSet command_bar = GetBSet(CommandBarWindowID); command_bar.window->visible = true; command_bar.window->eval_command = true; ActiveWindowID = command_bar.window->id; ResetBuffer(command_bar.buffer); For(CommandFunctions) { - Appendf(command_bar.view, "%S\n", it.name); + RawAppendf(command_bar.buffer, "%S\n", it.name); } command_bar.view->update_scroll = true; SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer)); } RegisterCommand(Command_ShowCommands, "ctrl-shift-p"); void Command_ShowBufferList() { + if (ActiveWindowID == CommandBarWindowID && LastExecutedCommand == Command_ShowBufferList) { + ActiveWindowID = LastActiveLayoutWindowID; + return; + } + BSet command_bar = GetBSet(CommandBarWindowID); command_bar.window->visible = true; command_bar.window->eval_command = false;