From 20d71722ea14e7cf1ddbbb4ee94e9aae9f5b220a Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sun, 22 Mar 2026 10:12:36 +0100 Subject: [PATCH] GC temp buffers after they are 25th in history --- src/plugin_file_commands.cpp | 1 + src/ui.cpp | 1 + src/view.cpp | 26 +++++++++++++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/plugin_file_commands.cpp b/src/plugin_file_commands.cpp index 9236463..12dc8a2 100644 --- a/src/plugin_file_commands.cpp +++ b/src/plugin_file_commands.cpp @@ -15,6 +15,7 @@ void New(Window *window, String name = "") { name = GetUniqueBufferName(dir, "new"); } WindowOpenBufferView(window, name); + RunGCThisFrame = true; } void CMD_New() { diff --git a/src/ui.cpp b/src/ui.cpp index 25777ad..44153f4 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -5,6 +5,7 @@ void JumpTempBuffer(BSet *set, String buffer_name) { set->view = WindowOpenBufferView(set->window, buffer_name); set->buffer = GetBuffer(set->view->active_buffer); set->buffer->temp = true; + RunGCThisFrame = true; } void AddCommand(Array *arr, String name, Trigger *trigger, CMDFunction *function) { diff --git a/src/view.cpp b/src/view.cpp index e6e09b5..d3267d0 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -103,6 +103,22 @@ API bool ViewIsCrumb(ViewID view_id) { return false; } + +API Int GetViewReferencedInHistoryRating(ViewID view_id) { + ForItem (window, Windows) { + For (window->goto_redo) if (it.view_id == view_id) return 1; + Int i = 0; + For (window->goto_history) { + i += 1; + if (it.view_id == view_id) { + return i; + } + } + } + return 0; +} + + bool ViewIsActive(ViewID id) { For (Windows) { if (it->active_view == id) { @@ -112,16 +128,16 @@ bool ViewIsActive(ViewID id) { return false; } -API bool ViewIsReferenced(View *view) { +API Int ViewIsReferenced(View *view) { if (view->special) { - return true; + return 1; } - if (ViewIsCrumb(view->id)) { - return true; + if (ViewIsActive(view->id)) { + return 1; } - return ViewIsActive(view->id); + return GetViewReferencedInHistoryRating(view->id); } bool BufferIsReferenced(Buffer *buffer) {