aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/UndoHistory.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2024-02-01 09:36:08 +1100
committerNeil <nyamatongwe@gmail.com>2024-02-01 09:36:08 +1100
commit252cb0fe25a8cbbce19944033e311203e0fb07dc (patch)
tree49607a3c6cd32981b5ea53598623e706097251ff /src/UndoHistory.cxx
parentc6b542f84e65083552e52768db7bb4c11dcd7a64 (diff)
downloadscintilla-mirror-252cb0fe25a8cbbce19944033e311203e0fb07dc.tar.gz
Add UndoAction class as internal type for undo actions and make Action a struct
that is used for reporting undo steps to Document. This will allow further minimization of undo memory use.
Diffstat (limited to 'src/UndoHistory.cxx')
-rw-r--r--src/UndoHistory.cxx25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/UndoHistory.cxx b/src/UndoHistory.cxx
index 6b8c65165..d667c9b4d 100644
--- a/src/UndoHistory.cxx
+++ b/src/UndoHistory.cxx
@@ -36,6 +36,25 @@
namespace Scintilla::Internal {
+UndoAction::UndoAction() noexcept = default;
+
+void UndoAction::Create(ActionType at_, Sci::Position position_, const char *data_, Sci::Position lenData_, bool mayCoalesce_) {
+ position = position_;
+ at = at_;
+ mayCoalesce = mayCoalesce_;
+ lenData = lenData_;
+ data = nullptr;
+ if (lenData_) {
+ data = std::make_unique<char[]>(lenData_);
+ memcpy(&data[0], data_, lenData_);
+ }
+}
+
+void UndoAction::Clear() noexcept {
+ data = nullptr;
+ lenData = 0;
+}
+
// The undo history stores a sequence of user operations that represent the user's view of the
// commands executed on the text.
// Each user operation contains a sequence of text insertion and text deletion actions.
@@ -94,7 +113,7 @@ const char *UndoHistory::AppendAction(ActionType at, Sci::Position position, con
if (0 == undoSequenceDepth) {
// Top level actions may not always be coalesced
ptrdiff_t targetAct = -1;
- const Action *actPrevious = &(actions[currentAction + targetAct]);
+ const UndoAction *actPrevious = &(actions[currentAction + targetAct]);
// Container actions may forward the coalesce state of Scintilla Actions.
while ((actPrevious->at == ActionType::container) && actPrevious->mayCoalesce) {
targetAct--;
@@ -259,7 +278,7 @@ int UndoHistory::StartUndo() noexcept {
return currentAction - act;
}
-const Action &UndoHistory::GetUndoStep() const noexcept {
+const UndoAction &UndoHistory::GetUndoStep() const noexcept {
return actions[currentAction];
}
@@ -284,7 +303,7 @@ int UndoHistory::StartRedo() noexcept {
return act - currentAction;
}
-const Action &UndoHistory::GetRedoStep() const noexcept {
+const UndoAction &UndoHistory::GetRedoStep() const noexcept {
return actions[currentAction];
}