Skip to content

Commit

Permalink
add a lambda for multi-click selections
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Jun 3, 2020
1 parent d31a377 commit 39c944d
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 39c944d

Please sign in to comment.