From 724429a7c661eeafe3094a049f747267d0496a69 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 8 Dec 2025 14:38:07 +1100 Subject: Bug [#2488]. Fix SCI_SETSELECTIONNSTART and SCI_SETSELECTIONNEND. --- src/Editor.cxx | 4 ++-- src/Selection.cxx | 28 ++++++++++++++++++++++++++++ src/Selection.h | 2 ++ 3 files changed, 32 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Editor.cxx b/src/Editor.cxx index e7a309e67..1ad99c3ca 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -6178,11 +6178,11 @@ void Editor::SetSelectionNMessage(Message iMessage, uptr_t wParam, sptr_t lParam break; case Message::SetSelectionNStart: - sel.Range(wParam).anchor.SetPosition(lParam); + sel.Range(wParam).StartSet(SelectionPosition(lParam)); break; case Message::SetSelectionNEnd: - sel.Range(wParam).caret.SetPosition(lParam); + sel.Range(wParam).EndSet(SelectionPosition(lParam)); break; default: diff --git a/src/Selection.cxx b/src/Selection.cxx index 967033bff..e8d0148f5 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -182,6 +182,34 @@ SelectionSegment SelectionRange::Intersect(SelectionSegment check) const noexcep }; } +void SelectionRange::StartSet(SelectionPosition sp) noexcept { + if (anchor <= caret) { + anchor = sp; + if (caret < anchor) { + caret = anchor; + } + } else { + caret = sp; + if (anchor < caret) { + anchor = caret; + } + } +} + +void SelectionRange::EndSet(SelectionPosition sp) noexcept { + if (caret >= anchor) { + caret = sp; + if (anchor > caret) { + anchor = caret; + } + } else { + anchor = sp; + if (caret > anchor) { + caret = anchor; + } + } +} + void SelectionRange::Swap() noexcept { std::swap(caret, anchor); } diff --git a/src/Selection.h b/src/Selection.h index 1a57d2e78..0b3bb9159 100644 --- a/src/Selection.h +++ b/src/Selection.h @@ -156,6 +156,8 @@ struct SelectionRange { SelectionPosition End() const noexcept { return (anchor < caret) ? caret : anchor; } + void StartSet(SelectionPosition sp) noexcept; + void EndSet(SelectionPosition sp) noexcept; void Swap() noexcept; bool Trim(SelectionRange range) noexcept; void Truncate(Sci::Position length) noexcept; -- cgit v1.2.3