summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2023-04-14 16:54:11 +0200
committerMatthias Melcher <github@matthiasm.com>2023-04-14 16:54:11 +0200
commite18b5353cd1931421db376ac4ace4000dfffa86c (patch)
tree21287b785750561712a051a41f18e75064682e66
parentafd3fde5de41cd5c10e0953e25976912cf4cf25f (diff)
Fixed leak in Fl_Text_Buffer #716
-rw-r--r--FL/Fl_Text_Buffer.H18
-rw-r--r--src/Fl_Text_Buffer.cxx24
-rw-r--r--src/Fl_Text_Display.cxx2
3 files changed, 40 insertions, 4 deletions
diff --git a/FL/Fl_Text_Buffer.H b/FL/Fl_Text_Buffer.H
index dabe5677a..4a0d0034b 100644
--- a/FL/Fl_Text_Buffer.H
+++ b/FL/Fl_Text_Buffer.H
@@ -328,12 +328,28 @@ public:
int undo(int *cp=0);
/**
+ Check if undo is anabled and if the last action can be undone.
+ \see canUndo()
+ */
+ bool can_undo();
+
+ /**
Redo previous undo action.
*/
int redo(int *cp=0);
/**
- Lets the undo system know if we can undo changes
+ Check if undo is anabled and if the last undo action can be redone.
+ \see canUndo()
+ */
+ bool can_redo();
+
+ /**
+ Enable or disable undo actions for this text buffer.
+ Undo actions are enable for text buffer by default. If used as a style buffer
+ in Fl_Text_Display, undo actions are disabled as they are handled by the
+ text buffer.
+ \see can_undo()
*/
void canUndo(char flag=1);
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());
}
/*
diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx
index c49434c79..029d7fef9 100644
--- a/src/Fl_Text_Display.cxx
+++ b/src/Fl_Text_Display.cxx
@@ -442,8 +442,6 @@ void Fl_Text_Display::highlight_data(Fl_Text_Buffer *styleBuffer,
damage(FL_DAMAGE_EXPOSE);
}
-
-
/**
\brief Find the longest line of all visible lines.