From 39c944d01bda52af4488b72cd71fe98162418e7f Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Wed, 3 Jun 2020 11:20:03 -0700 Subject: [PATCH] add a lambda for multi-click selections --- src/cascadia/TerminalControl/TermControl.cpp | 33 +++++++++----------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index cf79361b539..5beeb6ec0f5 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -968,34 +968,31 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation auto clickCount = _NumberOfClicks(cursorPosition, point.Timestamp()); - // This formula enables the number of clicks to cycle properly between single-, double-, and triple-click. - // To increase the number of acceptable click states, simply increment MAX_CLICK_COUNT and add another if-statement - const unsigned int MAX_CLICK_COUNT = 3; - const auto multiClickMapper = clickCount > MAX_CLICK_COUNT ? ((clickCount + MAX_CLICK_COUNT - 1) % MAX_CLICK_COUNT) + 1 : clickCount; - - if (multiClickMapper == 3) - { + // performs a double/triple click selection + auto multiClickSelection = [this, terminalPosition, shiftEnabled](::Terminal::SelectionExpansionMode mode) { if (shiftEnabled && _terminal->IsSelectionActive()) { - _terminal->SetSelectionEnd(terminalPosition, ::Terminal::SelectionExpansionMode::Line); + _terminal->SetSelectionEnd(terminalPosition, mode); } else { - _terminal->MultiClickSelection(terminalPosition, ::Terminal::SelectionExpansionMode::Line); + _terminal->MultiClickSelection(terminalPosition, mode); } _selectionNeedsToBeCopied = true; + }; + + // This formula enables the number of clicks to cycle properly between single-, double-, and triple-click. + // To increase the number of acceptable click states, simply increment MAX_CLICK_COUNT and add another if-statement + const unsigned int MAX_CLICK_COUNT = 3; + const auto multiClickMapper = clickCount > MAX_CLICK_COUNT ? ((clickCount + MAX_CLICK_COUNT - 1) % MAX_CLICK_COUNT) + 1 : clickCount; + + if (multiClickMapper == 3) + { + multiClickSelection(::Terminal::SelectionExpansionMode::Line); } else if (multiClickMapper == 2) { - if (shiftEnabled && _terminal->IsSelectionActive()) - { - _terminal->SetSelectionEnd(terminalPosition, ::Terminal::SelectionExpansionMode::Word); - } - else - { - _terminal->MultiClickSelection(terminalPosition, ::Terminal::SelectionExpansionMode::Word); - } - _selectionNeedsToBeCopied = true; + multiClickSelection(::Terminal::SelectionExpansionMode::Word); } else {