aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Selection.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2025-02-05 12:37:59 +1100
committerNeil <nyamatongwe@gmail.com>2025-02-05 12:37:59 +1100
commitac415de8e8457471528908f73996be78613c4620 (patch)
tree4c80b3ad47b2af01d085ba96260020c76745f9a4 /src/Selection.cxx
parent3b6cb53b53977939b47eda34fd1d16a91e6517ec (diff)
downloadscintilla-mirror-ac415de8e8457471528908f73996be78613c4620.tar.gz
Simplify SelectionRange::Intersect and add SelectionRange constructor from
positions without virtual space. Add unit tests.
Diffstat (limited to 'src/Selection.cxx')
-rw-r--r--src/Selection.cxx23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/Selection.cxx b/src/Selection.cxx
index 7b517cc4a..20fb1efca 100644
--- a/src/Selection.cxx
+++ b/src/Selection.cxx
@@ -170,20 +170,15 @@ bool SelectionRange::ContainsCharacter(SelectionPosition spCharacter) const noex
}
SelectionSegment SelectionRange::Intersect(SelectionSegment check) const noexcept {
- const SelectionSegment inOrder(caret, anchor);
- if ((inOrder.start <= check.end) || (inOrder.end >= check.start)) {
- SelectionSegment portion = check;
- if (portion.start < inOrder.start)
- portion.start = inOrder.start;
- if (portion.end > inOrder.end)
- portion.end = inOrder.end;
- if (portion.start > portion.end)
- return SelectionSegment();
- else
- return portion;
- } else {
- return SelectionSegment();
- }
+ const SelectionSegment inOrder = AsSegment();
+ if ((inOrder.start > check.end) || (inOrder.end < check.start)) {
+ // Nothing in common, not even touching so return empty *invalid* segment
+ return {};
+ }
+ return {
+ std::max(check.start, inOrder.start),
+ std::min(check.end, inOrder.end)
+ };
}
void SelectionRange::Swap() noexcept {