1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-22 17:48:01 +02:00

Slightly better handling of clicking within a selection

This commit is contained in:
Brian Fiete 2022-03-31 08:42:57 -07:00
parent 394a7e0bc5
commit 6d12b42456

View file

@ -751,11 +751,21 @@ namespace Beefy.widgets
public override void MouseDown(float x, float y, int32 btn, int32 btnCount) public override void MouseDown(float x, float y, int32 btn, int32 btnCount)
{ {
bool hadSelection = HasSelection();
base.MouseDown(x, y, btn, btnCount); base.MouseDown(x, y, btn, btnCount);
mEditWidget.SetFocus(); 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))) if ((mSelection == null) && (mWidgetWindow.IsKeyDown(KeyCode.Shift)))
StartSelection(); StartSelection();
@ -809,15 +819,6 @@ namespace Beefy.widgets
} }
else if (!mWidgetWindow.IsKeyDown(KeyCode.Shift)) 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 else
@ -832,7 +833,10 @@ namespace Beefy.widgets
{ {
mDragSelectionUnion = null; mDragSelectionUnion = null;
if ((mDragSelectionKind == .ClickedInside) && (btn == 0)) if ((mDragSelectionKind == .ClickedInside) && (btn == 0))
{
mSelection = null; mSelection = null;
MoveCursorToCoord(x, y);
}
mDragSelectionKind = .None; mDragSelectionKind = .None;
} }
} }
@ -843,12 +847,15 @@ namespace Beefy.widgets
if ((mMouseDown) && (mMouseFlags == .Left)) if ((mMouseDown) && (mMouseFlags == .Left))
{ {
if (mDragSelectionKind == .ClickedInside)
mDragSelectionKind = .DraggingInside;
if (mDragSelectionKind == .DraggingInside)
return;
MoveCursorToCoord(x, y); MoveCursorToCoord(x, y);
ClampCursor(); ClampCursor();
if (mDragSelectionKind == .Dragging) if (mDragSelectionKind == .Dragging)
SelectToCursor(); SelectToCursor();
else if (mDragSelectionKind == .ClickedInside)
mDragSelectionKind = .DraggingInside;
} }
} }