diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Editor.cxx | 25 | ||||
-rw-r--r-- | src/Editor.h | 1 | ||||
-rw-r--r-- | src/Selection.cxx | 7 | ||||
-rw-r--r-- | src/Selection.h | 1 |
4 files changed, 34 insertions, 0 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 627179876..527c9b47c 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -4511,6 +4511,28 @@ bool Editor::PointInSelection(Point pt) { return false; } +ptrdiff_t Editor::SelectionFromPoint(Point pt) { + // Prioritize checking inside non-empty selections since each character will be inside only 1 + const SelectionPosition posChar = SPositionFromLocation(pt, true, true); + for (size_t r = 0; r < sel.Count(); r++) { + if (sel.Range(r).ContainsCharacter(posChar)) { + return r; + } + } + + // Then check if near empty selections as may be near more than 1 + const SelectionPosition pos = SPositionFromLocation(pt, true, false); + for (size_t r = 0; r < sel.Count(); r++) { + const SelectionRange &range = sel.Range(r); + if ((range.Empty()) && (pos == range.caret)) { + return r; + } + } + + // No selection at point + return -1; +} + bool Editor::PointInSelMargin(Point pt) const { // Really means: "Point in a margin" if (vs.fixedColumnWidth > 0) { // There is a margin @@ -8676,6 +8698,9 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { Redraw(); break; + case Message::SelectionFromPoint: + return SelectionFromPoint(PointFromParameters(wParam, lParam)); + case Message::DropSelectionN: sel.DropSelection(wParam); ContainerNeedsUpdate(Update::Selection); diff --git a/src/Editor.h b/src/Editor.h index e7e198aec..19b0c730c 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -527,6 +527,7 @@ protected: // ScintillaBase subclass needs access to much of Editor /** PositionInSelection returns true if position in selection. */ bool PositionInSelection(Sci::Position pos); bool PointInSelection(Point pt); + ptrdiff_t SelectionFromPoint(Point pt); bool PointInSelMargin(Point pt) const; Window::Cursor GetMarginCursor(Point pt) const noexcept; void TrimAndSetSelection(Sci::Position currentPos_, Sci::Position anchor_); diff --git a/src/Selection.cxx b/src/Selection.cxx index fbdc474eb..53559e329 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -123,6 +123,13 @@ bool SelectionRange::ContainsCharacter(Sci::Position posCharacter) const noexcep return (posCharacter >= anchor.Position()) && (posCharacter < caret.Position()); } +bool SelectionRange::ContainsCharacter(SelectionPosition spCharacter) const noexcept { + if (anchor > caret) + return (spCharacter >= caret) && (spCharacter < anchor); + else + return (spCharacter >= anchor) && (spCharacter < caret); +} + SelectionSegment SelectionRange::Intersect(SelectionSegment check) const noexcept { const SelectionSegment inOrder(caret, anchor); if ((inOrder.start <= check.end) || (inOrder.end >= check.start)) { diff --git a/src/Selection.h b/src/Selection.h index 30e1e27ad..03ce5083c 100644 --- a/src/Selection.h +++ b/src/Selection.h @@ -129,6 +129,7 @@ struct SelectionRange { bool Contains(Sci::Position pos) const noexcept; bool Contains(SelectionPosition sp) const noexcept; bool ContainsCharacter(Sci::Position posCharacter) const noexcept; + bool ContainsCharacter(SelectionPosition spCharacter) const noexcept; SelectionSegment Intersect(SelectionSegment check) const noexcept; SelectionPosition Start() const noexcept { return (anchor < caret) ? anchor : caret; |