From 026058ceca31c336a6d76f248ae2510fe1b1247c Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 6 Nov 2023 08:31:47 +1100 Subject: Simplify variable flow in ButtonDownWithModifiers and enforce with const to make adding features easier. Does not change behaviour. --- src/Editor.cxx | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Editor.cxx b/src/Editor.cxx index d65c8aea3..3018cc0bd 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -4657,10 +4657,10 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, KeyMod modi const bool ctrl = FlagSet(modifiers, KeyMod::Ctrl); const bool shift = FlagSet(modifiers, KeyMod::Shift); const bool alt = FlagSet(modifiers, KeyMod::Alt); - SelectionPosition newPos = SPositionFromLocation(pt, false, false, AllowVirtualSpace(virtualSpaceOptions, alt)); - newPos = MovePositionOutsideChar(newPos, sel.MainCaret() - newPos.Position()); - SelectionPosition newCharPos = SPositionFromLocation(pt, false, true, false); - newCharPos = MovePositionOutsideChar(newCharPos, -1); + const SelectionPosition clickPos = SPositionFromLocation(pt, false, false, AllowVirtualSpace(virtualSpaceOptions, alt)); + const SelectionPosition newPos = MovePositionOutsideChar(clickPos, sel.MainCaret() - clickPos.Position()); + const SelectionPosition newCharPos = MovePositionOutsideChar( + SPositionFromLocation(pt, false, true, false), -1); inDragDrop = DragDrop::none; sel.SetMoveExtends(false); @@ -4669,18 +4669,20 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, KeyMod modi NotifyIndicatorClick(true, newPos.Position(), modifiers); + const bool multiClick = (curTime < (lastClickTime + Platform::DoubleClickTime())) && Close(pt, lastClick, doubleClickCloseThreshold); + lastClickTime = curTime; + lastClick = pt; + const bool inSelMargin = PointInSelMargin(pt); // In margin ctrl+(double)click should always select everything if (ctrl && inSelMargin) { SelectAll(); - lastClickTime = curTime; - lastClick = pt; return; } if (shift && !inSelMargin) { SetSelection(newPos); } - if ((curTime < (lastClickTime+Platform::DoubleClickTime())) && Close(pt, lastClick, doubleClickCloseThreshold)) { + if (multiClick) { //Platform::DebugPrintf("Double click %d %d = %d\n", curTime, lastClickTime, curTime - lastClickTime); ChangeMouseCapture(true); if (!ctrl || !multipleSelection || (selectionUnit != TextUnit::character && selectionUnit != TextUnit::word)) @@ -4787,10 +4789,9 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, KeyMod modi hotSpotClickPos = newCharPos.Position(); } if (!shift) { - if (PointInSelection(pt) && !SelectionEmpty()) + if (PointInSelection(pt) && !SelectionEmpty()) { inDragDrop = DragDrop::initial; - else - inDragDrop = DragDrop::none; + } } ChangeMouseCapture(true); if (inDragDrop != DragDrop::initial) { @@ -4822,8 +4823,6 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, KeyMod modi } } } - lastClickTime = curTime; - lastClick = pt; lastXChosen = static_cast(pt.x) + xOffset; ShowCaretAtCurrentPosition(); } -- cgit v1.2.3