diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Editor.cxx | 4 | ||||
-rw-r--r-- | src/Selection.cxx | 13 | ||||
-rw-r--r-- | src/Selection.h | 7 |
3 files changed, 22 insertions, 2 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 61008613d..45cf73bec 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -4685,7 +4685,7 @@ int Editor::KeyCommand(unsigned int iMessage) { MovePositionTo(MovePositionSoVisible(SelectionPosition(sel.MainCaret() - 1), -1)); } } else { - MovePositionTo(sel.RangeMain().Start()); + MovePositionTo(sel.IsRectangular() ? sel.Limits().start : sel.RangeMain().Start()); } SetLastXChosen(); break; @@ -4719,7 +4719,7 @@ int Editor::KeyCommand(unsigned int iMessage) { MovePositionTo(MovePositionSoVisible(SelectionPosition(sel.MainCaret() + 1), 1)); } } else { - MovePositionTo(sel.RangeMain().End()); + MovePositionTo(sel.IsRectangular() ? sel.Limits().end : sel.RangeMain().End()); } SetLastXChosen(); break; diff --git a/src/Selection.cxx b/src/Selection.cxx index 47d078675..566cb1074 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -179,6 +179,19 @@ SelectionRange &Selection::Rectangular() { return rangeRectangular; } +SelectionSegment Selection::Limits() const { + if (ranges.empty()) { + return SelectionSegment(); + } else { + SelectionSegment sr(ranges[0].anchor, ranges[0].caret); + for (size_t i=1; i<ranges.size(); i++) { + sr.Extend(ranges[i].anchor); + sr.Extend(ranges[i].caret); + } + return sr; + } +} + size_t Selection::Count() const { return ranges.size(); } diff --git a/src/Selection.h b/src/Selection.h index b0c286866..d064af642 100644 --- a/src/Selection.h +++ b/src/Selection.h @@ -74,6 +74,12 @@ struct SelectionSegment { bool Empty() const { return start == end; } + void Extend(SelectionPosition p) { + if (start > p) + start = p; + if (end < p) + end = p; + } }; struct SelectionRange { @@ -141,6 +147,7 @@ public: int MainCaret() const; int MainAnchor() const; SelectionRange &Rectangular(); + SelectionSegment Limits() const; size_t Count() const; size_t Main() const; void SetMain(size_t r); |