From f54fd2019dd648b29a80ec7429833ab546d3a428 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 1 Feb 2025 14:43:22 +1100 Subject: Serialize selection type and ranges with SCI_GETSELECTIONSERIALIZED and SCI_SETSELECTIONSERIALIZED. --- src/Selection.cxx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/Selection.cxx') diff --git a/src/Selection.cxx b/src/Selection.cxx index 5650d5c7e..7b517cc4a 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -225,6 +225,13 @@ bool SelectionRange::Trim(SelectionRange range) noexcept { } } +void SelectionRange::Truncate(Sci::Position length) noexcept { + if (anchor.Position() > length) + anchor.SetPosition(length); + if (caret.Position() > length) + caret.SetPosition(length); +} + // If range is all virtual collapse to start of virtual space void SelectionRange::MinimizeVirtualSpace() noexcept { if (caret.Position() == anchor.Position()) { @@ -568,6 +575,16 @@ void Selection::SetRanges(const Ranges &rangesToSet) { ranges = rangesToSet; } +void Selection::Truncate(Sci::Position length) noexcept { + // This may be needed when applying a persisted selection onto a document that has been shortened. + for (SelectionRange &range : ranges) { + range.Truncate(length); + } + // Above may have made some non-unique empty ranges. + RemoveDuplicates(); + rangeRectangular.Truncate(length); +} + std::string Selection::ToString() const { std::string result; switch (selType) { -- cgit v1.2.3