From 80ea09b3eab7cfa5d3328d3b7740f6842a6ae5f2 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Mon, 5 Jan 2026 10:30:17 +0100 Subject: [PATCH] Improving the jump history --- src/backup/todo.txt | 3 +-- src/text_editor/buffer.cpp | 4 ++-- src/text_editor/commands.cpp | 2 +- src/text_editor/globals.cpp | 2 +- src/text_editor/text_editor.cpp | 22 +++++++++++++++++----- src/text_editor/window.cpp | 4 ++-- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/backup/todo.txt b/src/backup/todo.txt index 355bb49..06c1f02 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -7,10 +7,9 @@ - Remedybg commands integrated! (like clicking f5 and opening up the window) - Variable documentation ????? not looking too good due to formatting - OnUpdate view hooks! -- JumpHistory maybe a smarter algorithm is needed, like accept only if line also changed - Macros - ctrl-shift-f should insert the selected into search -- jump history batching doesn't work ... +- ctrl-e started doing no-ops again ... Use session 4 - ListVariables instead of GenerateConfig, auto saving of variables diff --git a/src/text_editor/buffer.cpp b/src/text_editor/buffer.cpp index 8ae035d..268e0e2 100644 --- a/src/text_editor/buffer.cpp +++ b/src/text_editor/buffer.cpp @@ -952,7 +952,7 @@ API void RedoEdit(Buffer *buffer, Array *carets) { if (buffer->redo_stack.len > 0) { HistoryEntry *next = GetLast(buffer->redo_stack); - if (next->time - entry.time <= UndoMergeTime) { + if ((next->time - entry.time) <= UndoMergeTime) { RedoEdit(buffer, carets); } } @@ -978,7 +978,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 <= UndoMergeTime) { + if ((entry.time - next->time) <= UndoMergeTime) { UndoEdit(buffer, carets); } } diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index bee17ef..ae1dd3b 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -856,7 +856,7 @@ void CMD_SetWorkDirHere() { } RegisterCommand(CMD_SetWorkDirHere, "", "Sets work directory to the directory of the current buffer, it also renames couple special buffers to make them accomodate the new WorkDir"); void Coro_OpenCode(mco_coro *co) { - Array patterns = Split(CoCurr->arena, NonCodePatterns_EndsWith, "|"); + Array patterns = Split(CoCurr->arena, OpenCodeCommandExcludePatterns, "|"); Array dirs = {CoCurr->arena}; String *param_dir = (String *)CoCurr->user_ctx; Add(&dirs, *param_dir); diff --git a/src/text_editor/globals.cpp b/src/text_editor/globals.cpp index 925d1e9..0a50165 100644 --- a/src/text_editor/globals.cpp +++ b/src/text_editor/globals.cpp @@ -163,7 +163,7 @@ RegisterVariable(String, WindowsVCVarsPathToLoadDevEnviroment, "C:/Program Files RegisterVariable(Float, UndoMergeTime, 0.3); RegisterVariable(Float, JumpHistoryMergeTime, 0.3); RegisterVariable(String, InternetBrowser, "firefox"); -RegisterVariable(String, NonCodePatterns_EndsWith, ".git/|.obj|.o|.pdb|.exe|.ilk|.ttf|.ico|.gif|.jpg|.png|.spall|.dll|.so|.a|.lib"); +RegisterVariable(String, OpenCodeCommandExcludePatterns, ".git/|.obj|.o|.pdb|.exe|.ilk|.ttf|.ico|.gif|.jpg|.png|.spall|.dll|.so|.a|.lib"); RegisterVariable(Int, TrimTrailingWhitespace, 1); RegisterVariable(Int, FormatCode, 0); RegisterVariable(Int, SetModifiesConfig, 1); \ No newline at end of file diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 9e8e097..04e28c3 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -613,12 +613,24 @@ void Update(Event event) { For (Windows) { if (it->jump_history) { View *view = GetView(it->active_view); - bool are_equal = it->begin_frame_crumb.view_id == it->active_view && AreEqual(view->carets[0], it->begin_frame_crumb.caret); - if (!are_equal) { - if (!it->skip_checkpoint) { - Add(&it->goto_history, it->begin_frame_crumb); - it->goto_redo.len = 0; + bool should_checkpoint = true; + if (it->skip_checkpoint) { + should_checkpoint = false; + } + if (should_checkpoint && it->begin_frame_crumb.view_id == it->active_view) { + if (AreEqual(view->carets[0], it->begin_frame_crumb.caret)) { + should_checkpoint = false; } + + Buffer *buffer = GetBuffer(view->active_buffer); + if (PosToLine(buffer, GetFront(view->main_caret_on_begin_frame)) == PosToLine(buffer, GetFront(view->carets[0]))) { + should_checkpoint = false; + } + } + + if (should_checkpoint) { + Add(&it->goto_history, it->begin_frame_crumb); + it->goto_redo.len = 0; } it->skip_checkpoint = false; } diff --git a/src/text_editor/window.cpp b/src/text_editor/window.cpp index 897b593..724b226 100644 --- a/src/text_editor/window.cpp +++ b/src/text_editor/window.cpp @@ -278,7 +278,7 @@ void JumpBack(Window *window) { if (window->goto_history.len) { GotoCrumb *next = GetLast(window->goto_history); - if (c.view_id == next->view_id && c.time - next->time <= JumpHistoryMergeTime) { + if (c.view_id == next->view_id && ((c.time - next->time) <= JumpHistoryMergeTime)) { JumpBack(window); } } @@ -298,7 +298,7 @@ void JumpForward(Window *window) { if (window->goto_redo.len) { GotoCrumb *next = GetLast(window->goto_redo); - if (c.view_id == next->view_id && next->time - c.time <= JumpHistoryMergeTime) { + if ((c.view_id == next->view_id) && ((next->time - c.time) <= JumpHistoryMergeTime)) { JumpForward(window); } }