From 5e51e2fbadf4205d48f39a8f73b05e133500bae4 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Thu, 15 Aug 2024 08:22:56 +0200 Subject: [PATCH] Auto enclose --- src/text_editor/commands.cpp | 7 ++++--- src/text_editor/commands_bindings.cpp | 6 ++++-- src/text_editor/text_editor.h | 1 + src/text_editor/todo.txt | 1 - 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 53417cf..7cb145a 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -888,9 +888,10 @@ void Command_FuzzySort(View *view, String16 needle) { } void Command_SelectTitlebarCommand(Window *window, String16 needle) { - BSet title = GetTitleSet(window); - String16 buffer_string = GetString(title.buffer); - ActiveWindow = title.window->id; + BSet title = GetTitleSet(window); + String16 buffer_string = GetString(title.buffer); + ActiveWindow = title.window->id; + title.window->auto_enclose = true; Scratch scratch; String16 quoted16 = {}; diff --git a/src/text_editor/commands_bindings.cpp b/src/text_editor/commands_bindings.cpp index b376f77..0de5b90 100644 --- a/src/text_editor/commands_bindings.cpp +++ b/src/text_editor/commands_bindings.cpp @@ -261,7 +261,8 @@ void GlobalCommand(Event event) { if (window) ActiveWindow = window->id; } - BSet active = GetActiveSet(); + BSet active = GetActiveSet(); + Int buffer_change_id = active.buffer->change_id; if (event.kind == EVENT_DROP_FILE) { WindowOpenBufferView(active.window, event.text); @@ -456,7 +457,8 @@ void GlobalCommand(Event event) { GotoBackward(GetActiveMainSet().window); } - if (CtrlShift(SDLK_Q)) { + bool should_enclose = active.window->auto_enclose && (active.buffer->change_id != buffer_change_id); + if (should_enclose || CtrlShift(SDLK_Q)) { Caret caret = active.view->carets[0]; Range range = caret.range; if (GetSize(caret.range) == 0) range = EncloseExecWord(active.buffer, GetFront(caret)); diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index fed63d6..a68d206 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -95,6 +95,7 @@ struct Window { bool is_title_bar : 1; bool is_column : 1; + bool auto_enclose : 1; bool deactivate_on_escape : 1; }; }; diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index 0fefec6..5b70e95 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -6,7 +6,6 @@ - group history entries so the you can rollback through multiple ones at once and not waste time on skipping whitespace trimming or deleting every character - Fuzzy search buffer which uses titlebar as query! -- Gotos, jumping between views should preserve cursors, maybe just scroll - ReportWarning should be signaled visibly but you should be able to do things! no focus switching - OnWindowCommand allow config user to overwrite the WindowCommand keybinding, introduce his own