From 97b1cf9e739d8c86742b43e9b96cd9ac3df7f690 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sat, 10 Aug 2024 07:32:39 +0200 Subject: [PATCH] Fix infinite loop in GotoNextInList --- src/text_editor/commands.cpp | 9 +++++++-- src/text_editor/commands_window.cpp | 4 ++-- src/text_editor/todo.txt | 1 - 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 9204f6f..77e8465 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -89,14 +89,19 @@ void ToggleConsole() { } } -void CheckpointBeforeGoto(WindowID window_id) { +void CheckpointBeforeGoto(WindowID window_id, ViewID view_id) { Window *window = GetWindow(window_id); - View *view = GetView(window->active_view); + View *view = GetView(view_id); Buffer *buffer = GetBuffer(view->active_buffer); Add(&window->goto_history, {buffer->id, view->carets[0]}); window->goto_redo.len = 0; } +void CheckpointBeforeGoto(WindowID window_id) { + Window *window = GetWindow(window_id); + CheckpointBeforeGoto(window_id, window->active_view); +} + void GotoBackward(WindowID window_id) { Window *window = GetWindow(window_id); if (window->goto_history.len <= 0) return; diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index 492784d..a2a63bd 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -591,7 +591,6 @@ void Command_Find(View *seek_view, String16 needle, bool forward = true) { void Command_GotoNextInList(Window *window, Int line_offset = 1) { Assert(line_offset == 1 || line_offset == -1); ViewID active_view = window->active_view; - CheckpointBeforeGoto(window->id); View *view_goto = GetView(window->active_goto_list); window->active_view = view_goto->id; @@ -601,7 +600,7 @@ void Command_GotoNextInList(Window *window, Int line_offset = 1) { Int line = PosToLine(*buffer_goto, pos); bool opened = false; - for (Int i = line + line_offset; line + line_offset < buffer_goto->line_starts.len && line + line_offset >= 0; i += line_offset) { + for (Int i = line + line_offset; i >= 0 && i < buffer_goto->line_starts.len; i += line_offset) { Range line_range = GetLineRangeWithoutNL(*buffer_goto, line + line_offset); String16 line = GetString(*buffer_goto, line_range); view_goto->carets[0] = MakeCaret(line_range.min); @@ -611,6 +610,7 @@ void Command_GotoNextInList(Window *window, Int line_offset = 1) { IF_DEBUG(AssertRanges(view_goto->carets)); if (line.len == 0) continue; + CheckpointBeforeGoto(window->id, active_view); Open(line); opened = true; break; diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index 5becfee..0679149 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -1,7 +1,6 @@ - Remove pointers and use ViewIDs (enable array debug while doing this) - Remove console and command window, provide alternatives but unify the interface? -- Ctrl + . to chop a path from buffer name and open that - apply clang format - apply clang format on save - OnWindowCommand allow config user to overwrite the WindowCommand keybinding, introduce his own