diff options
Diffstat (limited to 'src/Editor.cxx')
-rw-r--r-- | src/Editor.cxx | 25 |
1 files changed, 25 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); |