From 0e944897c67995714279999d7664b35bfb52ad78 Mon Sep 17 00:00:00 2001 From: Ford Smith Date: Fri, 2 Apr 2021 17:26:37 -0400 Subject: [PATCH] UI: Add maximum number of items in undo/redo stack --- UI/undo-stack-obs.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/UI/undo-stack-obs.cpp b/UI/undo-stack-obs.cpp index 7d1365c1c..71acd67f0 100644 --- a/UI/undo-stack-obs.cpp +++ b/UI/undo-stack-obs.cpp @@ -2,6 +2,8 @@ #include +#define MAX_STACK_SIZE 5000 + undo_stack::undo_stack(ui_ptr ui) : ui(ui) {} void undo_stack::release() @@ -19,6 +21,13 @@ void undo_stack::add_action(const QString &name, undo_redo_cb undo, undo_redo_cb redo, std::string undo_data, std::string redo_data, func d) { + while (undo_items.size() >= MAX_STACK_SIZE) { + undo_redo_t item = undo_items.back(); + if (item.d) + item.d(true); + undo_items.pop_back(); + } + undo_redo_t n = {name, undo_data, redo_data, undo, redo, d}; undo_items.push_front(n);