From db6332fa9933244c45c44063afbdcccb462cfc03 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 1 Feb 2025 09:39:53 +1100 Subject: Use string form for selection undo history as it saves significant space. On average takes around 20% of SelectionSimple. --- src/Editor.cxx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/Editor.cxx') diff --git a/src/Editor.cxx b/src/Editor.cxx index 0d1a221cd..10c694990 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -2403,19 +2403,18 @@ void Editor::RestoreSelection(Sci::Position newPos, UndoRedo history) { if ((undoSelectionHistoryOption == UndoSelectionHistoryOption::Enabled) && modelState) { // Undo wants the element after the current as it just undid it const int index = pdoc->UndoCurrent() + (history == UndoRedo::undo ? 1 : 0); - const SelectionSimple *pss = modelState->SelectionFromStack(index, history); - if (pss) { - sel.selType = pss->selType; + const std::string_view ss = modelState->SelectionFromStack(index, history); + if (!ss.empty()) { + sel = Selection(ss); if (sel.IsRectangular()) { - sel.Rectangular() = pss->rangeRectangular; + const size_t mainForRectangular = sel.Main(); // Reconstitute ranges from rectangular range SetRectangularRange(); - } else { - sel.SetRanges(pss->ranges); + // Restore main if possible. + if (mainForRectangular < sel.Count()) { + sel.SetMain(mainForRectangular); + } } - // Unsure if this is safe with SetMain potentially failing if document doesn't appear the same. - // Maybe this can occur if the user changes font or wrap mode? - sel.SetMain(pss->mainRange); newPos = -1; // Used selection from stack so don't use position returned from undo/redo. } } -- cgit v1.2.3