From 6d12b42456447d2fc80fa7e8988b2210ba941bf7 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 31 Mar 2022 08:42:57 -0700 Subject: [PATCH] Slightly better handling of clicking within a selection --- BeefLibs/Beefy2D/src/widgets/EditWidget.bf | 35 +++++++++++++--------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf index de2618f5..955bc23e 100644 --- a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf +++ b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf @@ -751,11 +751,21 @@ namespace Beefy.widgets public override void MouseDown(float x, float y, int32 btn, int32 btnCount) { - bool hadSelection = HasSelection(); - base.MouseDown(x, y, btn, btnCount); mEditWidget.SetFocus(); + if (HasSelection()) + { + GetLineCharAtCoord(x, y, var line, var lineChar, ?); + int textPos = GetTextIdx(line, lineChar); + if ((textPos > mSelection.Value.MinPos) && (textPos < mSelection.Value.MaxPos)) + { + // Leave selection + mDragSelectionKind = .ClickedInside; + return; + } + } + if ((mSelection == null) && (mWidgetWindow.IsKeyDown(KeyCode.Shift))) StartSelection(); @@ -809,16 +819,7 @@ namespace Beefy.widgets } else if (!mWidgetWindow.IsKeyDown(KeyCode.Shift)) { - if ((mSelection != null) && (CursorTextPos > mSelection.Value.MinPos) && (CursorTextPos < mSelection.Value.MaxPos)) - { - if (hadSelection) - { - // Leave selection - mDragSelectionKind = .ClickedInside; - } - } - else - StartSelection(); + StartSelection(); } else SelectToCursor(); @@ -832,7 +833,10 @@ namespace Beefy.widgets { mDragSelectionUnion = null; if ((mDragSelectionKind == .ClickedInside) && (btn == 0)) + { mSelection = null; + MoveCursorToCoord(x, y); + } mDragSelectionKind = .None; } } @@ -843,12 +847,15 @@ namespace Beefy.widgets if ((mMouseDown) && (mMouseFlags == .Left)) { + if (mDragSelectionKind == .ClickedInside) + mDragSelectionKind = .DraggingInside; + if (mDragSelectionKind == .DraggingInside) + return; + MoveCursorToCoord(x, y); ClampCursor(); if (mDragSelectionKind == .Dragging) SelectToCursor(); - else if (mDragSelectionKind == .ClickedInside) - mDragSelectionKind = .DraggingInside; } }