From 26b60d88b6d848f3ba55ca046852e079be5fe3c6 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 5 Nov 2023 22:11:26 +1100 Subject: Add SCI_SELECTIONFROMPOINT for modifying multiple selections. --- src/Editor.cxx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/Editor.cxx') 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); -- cgit v1.2.3