From e18b5353cd1931421db376ac4ace4000dfffa86c Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Fri, 14 Apr 2023 16:54:11 +0200 Subject: Fixed leak in Fl_Text_Buffer #716 --- src/Fl_Text_Buffer.cxx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/Fl_Text_Buffer.cxx') diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx index e6eb70c55..2cfe6f1e3 100644 --- a/src/Fl_Text_Buffer.cxx +++ b/src/Fl_Text_Buffer.cxx @@ -158,6 +158,10 @@ public: clear(); } + int size() { + return list_size_; + } + void push(Fl_Text_Undo_Action* action) { if (list_size_ == list_capacity_) { list_capacity_ += 25; @@ -628,6 +632,13 @@ int Fl_Text_Buffer::undo(int *cursorPos) { return ret; } +/* + Check if undo is anabled and if the last action can be undone. + */ +bool Fl_Text_Buffer::can_undo() { + return (mCanUndo && mUndo && !mUndo->empty()); +} + /** Redo previous undo action. */ @@ -642,7 +653,18 @@ int Fl_Text_Buffer::redo(int *cursorPos) { // running the redo action will also generate a new undo action // Note: there is a slight chance that the current undo action and the // generated action merge into one. - return apply_undo(redo_action, cursorPos); + int ret = apply_undo(redo_action, cursorPos); + + delete redo_action; + return ret; +} + +/** + Check if undo is anabled and if the last undo action can be redone. + \see canUndo() + */ +bool Fl_Text_Buffer::can_redo() { + return (mCanUndo && mRedoList->size()); } /* -- cgit v1.2.3