From 3de9d37c7b8f4501558d309ada718dc52533e94c Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 22 Jan 2025 21:34:54 +1100 Subject: Bug [#1224]. Remember selection in undo history. SCI_SETSELECTIONUNDOHISTORY. --- src/EditModel.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/EditModel.h') diff --git a/src/EditModel.h b/src/EditModel.h index e36d26fb1..716fd5788 100644 --- a/src/EditModel.h +++ b/src/EditModel.h @@ -21,6 +21,41 @@ public: Caret() noexcept; }; +// Simplified version of selection which won't contain rectangular selection realized +// into ranges as too much data. +// Just a type and single range for now. + +struct SelectionSimple { + std::vector ranges; + SelectionRange rangeRectangular; + size_t mainRange = 0; + Selection::SelTypes selType = Selection::SelTypes::stream; + + SelectionSimple() = default; + explicit SelectionSimple(const Selection &sel); +}; + +enum class UndoRedo { undo, redo }; + +struct SelectionHistory { + int indexCurrent = 0; + SelectionSimple ssCurrent; + std::map stack; +}; + +struct ModelState : ViewState { + SelectionHistory historyForUndo; + SelectionHistory historyForRedo; + void RememberSelectionForUndo(int index, const Selection &sel); + void ForgetSelectionForUndo() noexcept; + void RememberSelectionOntoStack(int index); + void RememberSelectionForRedoOntoStack(int index, const Selection &sel); + const SelectionSimple *SelectionFromStack(int index, UndoRedo history) const; + virtual void TruncateUndo(int index) final; +}; + +using ModelStateShared = std::shared_ptr; + class EditModel { public: bool inOverstrike; @@ -57,6 +92,10 @@ public: Document *pdoc; + bool rememberingSelectionForUndo = false; + bool needRedoRemembered = false; + ModelStateShared modelState; + EditModel(); // Deleted so EditModel objects can not be copied. EditModel(const EditModel &) = delete; @@ -75,6 +114,8 @@ public: const char *GetFoldDisplayText(Sci::Line lineDoc) const noexcept; InSelection LineEndInSelection(Sci::Line lineDoc) const; [[nodiscard]] int GetMark(Sci::Line line) const; + + void EnsureModelState(); }; } -- cgit v1.2.3