diff options
author | Neil <nyamatongwe@gmail.com> | 2025-02-01 14:43:22 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2025-02-01 14:43:22 +1100 |
commit | f54fd2019dd648b29a80ec7429833ab546d3a428 (patch) | |
tree | 231bebba7db25fccf798340bdd908f28fd504c26 /src/Selection.cxx | |
parent | db6332fa9933244c45c44063afbdcccb462cfc03 (diff) | |
download | scintilla-mirror-f54fd2019dd648b29a80ec7429833ab546d3a428.tar.gz |
Serialize selection type and ranges with SCI_GETSELECTIONSERIALIZED and
SCI_SETSELECTIONSERIALIZED.
Diffstat (limited to 'src/Selection.cxx')
-rw-r--r-- | src/Selection.cxx | 17 |
1 files changed, 17 insertions, 0 deletions
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) { |