Skip to content

Commit

Permalink
remove configurability
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Sep 17, 2021
1 parent b13b8a7 commit 118d1cd
Show file tree
Hide file tree
Showing 20 changed files with 140 additions and 310 deletions.
44 changes: 1 addition & 43 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@
"toggleSplitOrientation",
"toggleReadOnlyMode",
"toggleShaderEffects",
"updateSelection",
"wt",
"quit",
"unbound"
Expand Down Expand Up @@ -333,24 +332,6 @@
],
"type": "string"
},
"SelectionDirection": {
"enum": [
"left",
"right",
"up",
"down"
],
"type": "string"
},
"SelectionMode": {
"enum": [
"char",
"word",
"view",
"buffer"
],
"type": "string"
},
"MoveTabDirection": {
"enum": [
"forward",
Expand Down Expand Up @@ -605,28 +586,6 @@
],
"required": [ "direction" ]
},
"UpdateSelectionAction": {
"description": "Arguments corresponding to a Update Selection Action",
"allOf": [
{ "$ref": "#/definitions/ShortcutAction" },
{
"properties": {
"action": { "type": "string", "pattern": "updateSelection" },
"direction": {
"$ref": "#/definitions/SelectionDirection",
"default": "left",
"description": "The direction to move the selection endpoint in."
},
"mode": {
"$ref": "#/definitions/SelectionMode",
"default": "cell",
"description": "The expansion mode to move the selection endpoint by."
}
}
}
],
"required": [ "direction" ]
},
"ResizePaneAction": {
"description": "Arguments corresponding to a Resize Pane Action",
"allOf": [
Expand Down Expand Up @@ -888,7 +847,7 @@
}
],
"required": [ "actions" ]
},
},
"CommandPaletteAction": {
"description": "Arguments for a commandPalette action",
"allOf": [
Expand Down Expand Up @@ -1107,7 +1066,6 @@
{ "$ref": "#/definitions/FocusPaneAction" },
{ "$ref": "#/definitions/GlobalSummonAction" },
{ "$ref": "#/definitions/QuakeModeAction" },
{ "$ref": "#/definitions/UpdateSelectionAction" },
{ "type": "null" }
]
},
Expand Down
15 changes: 0 additions & 15 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,19 +921,4 @@ namespace winrt::TerminalApp::implementation
}
}
}

void TerminalPage::_HandleUpdateSelection(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
if (args)
{
if (const auto& realArgs = args.ActionArgs().try_as<UpdateSelectionArgs>())
{
if (const auto termControl{ _GetActiveControl() })
{
args.Handled(termControl.UpdateSelection(realArgs.Direction(), realArgs.Mode()));
}
}
}
}
}
131 changes: 80 additions & 51 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,72 @@ constexpr const auto TsfRedrawInterval = std::chrono::milliseconds(100);
// The minimum delay between updating the locations of regex patterns
constexpr const auto UpdatePatternLocationsInterval = std::chrono::milliseconds(500);

static constexpr InternalSelectionDirection ConvertToInternalSelectionDirection(winrt::Microsoft::Terminal::Core::SelectionDirection dir)
static constexpr std::optional<Terminal::SelectionDirection> ConvertVKeyToSelectionDirection(WORD vkey)
{
switch (dir)
{
switch (vkey)
{
case VK_LEFT:
case VK_HOME:
return Terminal::SelectionDirection::Left;
case VK_RIGHT:
case VK_END:
return Terminal::SelectionDirection::Right;
case VK_UP:
case VK_PRIOR:
return Terminal::SelectionDirection::Up;
case VK_DOWN:
case VK_NEXT:
return Terminal::SelectionDirection::Down;
default:
case winrt::Microsoft::Terminal::Core::SelectionDirection::Left:
return InternalSelectionDirection::Left;
case winrt::Microsoft::Terminal::Core::SelectionDirection::Right:
return InternalSelectionDirection::Right;
case winrt::Microsoft::Terminal::Core::SelectionDirection::Up:
return InternalSelectionDirection::Up;
case winrt::Microsoft::Terminal::Core::SelectionDirection::Down:
return InternalSelectionDirection::Down;
return std::nullopt;
}
}

static constexpr InternalSelectionExpansion ConvertToInternalSelectionExpansion(winrt::Microsoft::Terminal::Core::SelectionExpansion mode)
static constexpr std::optional<std::tuple<Terminal::SelectionDirection, Terminal::SelectionExpansion>> ConvertKeyEventToUpdateSelectionParams(const ControlKeyStates mods, const WORD vkey)
{
switch (mode)
if (mods.IsShiftPressed() && !mods.IsAltPressed())
{
default:
case winrt::Microsoft::Terminal::Core::SelectionExpansion::Char:
return InternalSelectionExpansion::Char;
case winrt::Microsoft::Terminal::Core::SelectionExpansion::Word:
return InternalSelectionExpansion::Word;
case winrt::Microsoft::Terminal::Core::SelectionExpansion::Line:
return InternalSelectionExpansion::Line;
case winrt::Microsoft::Terminal::Core::SelectionExpansion::Viewport:
return InternalSelectionExpansion::Viewport;
case winrt::Microsoft::Terminal::Core::SelectionExpansion::Buffer:
return InternalSelectionExpansion::Buffer;
if (const auto dir{ ConvertVKeyToSelectionDirection(vkey) })
{
if (mods.IsCtrlPressed())
{
switch (vkey)
{
case VK_LEFT:
case VK_RIGHT:
// Move by word
return std::make_tuple(*dir, Terminal::SelectionExpansion::Word);
case VK_HOME:
case VK_END:
// Move by buffer
return std::make_tuple(*dir, Terminal::SelectionExpansion::Buffer);
default:
__fallthrough;
}
}
else
{
switch (vkey)
{
case VK_HOME:
case VK_END:
case VK_PRIOR:
case VK_NEXT:
// Move by viewport
return std::make_tuple(*dir, Terminal::SelectionExpansion::Viewport);
case VK_LEFT:
case VK_RIGHT:
case VK_UP:
case VK_DOWN:
// Move by character
return std::make_tuple(*dir, Terminal::SelectionExpansion::Char);
default:
__fallthrough;
}
}
}
}
return std::nullopt;
}

namespace winrt::Microsoft::Terminal::Control::implementation
Expand Down Expand Up @@ -393,28 +427,38 @@ namespace winrt::Microsoft::Terminal::Control::implementation
const ControlKeyStates modifiers,
const bool keyDown)
{
// When there is a selection active, escape should clear it and NOT flow through
// to the terminal. With any other keypress, it should clear the selection AND
// flow through to the terminal.
// Update the selection, if it's present
// GH#6423 - don't dismiss selection if the key that was pressed was a
// modifier key. We'll wait for a real keystroke to dismiss the
// GH #7395 - don't dismiss selection when taking PrintScreen
// selection.
// GH#8522, GH#3758 - Only dismiss the selection on key _down_. If we
// dismiss on key up, then there's chance that we'll immediately dismiss
// GH#8522, GH#3758 - Only modify the selection on key _down_. If we
// modify on key up, then there's chance that we'll immediately dismiss
// a selection created by an action bound to a keydown.
if (HasSelection() &&
!KeyEvent::IsModifierKey(vkey) &&
vkey != VK_SNAPSHOT &&
keyDown)
{
// try to update the selection
if (const auto updateSlnParams{ ConvertKeyEventToUpdateSelectionParams(modifiers, vkey) })
{
auto lock = _terminal->LockForWriting();
_terminal->UpdateSelection(std::get<0>(*updateSlnParams), std::get<1>(*updateSlnParams));
_renderer->TriggerSelection();
return true;
}

// GH#8791 - don't dismiss selection if Windows key was also pressed as a key-combination.
if (!modifiers.IsWinPressed())
{
_terminal->ClearSelection();
_renderer->TriggerSelection();
}

// When there is a selection active, escape should clear it and NOT flow through
// to the terminal. With any other keypress, it should clear the selection AND
// flow through to the terminal.
if (vkey == VK_ESCAPE)
{
return true;
Expand Down Expand Up @@ -961,21 +1005,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_renderer->TriggerSelection();
}

bool ControlCore::UpdateSelection(Core::SelectionDirection direction, Core::SelectionExpansion mode)
{
// - SelectionDirection cannot be none
// - A selection must be active for us to update it
if (direction == Core::SelectionDirection::None || !HasSelection())
{
return false;
}

auto lock = _terminal->LockForWriting();
_terminal->UpdateSelection(ConvertToInternalSelectionDirection(direction), ConvertToInternalSelectionExpansion(mode));
_renderer->TriggerSelection();
return true;
}

// Called when the Terminal wants to set something to the clipboard, i.e.
// when an OSC 52 is emitted.
void ControlCore::_terminalCopyToClipboard(std::wstring_view wstr)
Expand Down Expand Up @@ -1471,18 +1500,18 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// handle ALT key
_terminal->SetBlockSelection(altEnabled);

Core::SelectionExpansion mode = Core::SelectionExpansion::Char;
::Terminal::SelectionExpansion mode = ::Terminal::SelectionExpansion::Char;
if (numberOfClicks == 1)
{
mode = Core::SelectionExpansion::Char;
mode = ::Terminal::SelectionExpansion::Char;
}
else if (numberOfClicks == 2)
{
mode = Core::SelectionExpansion::Word;
mode = ::Terminal::SelectionExpansion::Word;
}
else if (numberOfClicks == 3)
{
mode = Core::SelectionExpansion::Line;
mode = ::Terminal::SelectionExpansion::Line;
}

// Update the selection appropriately
Expand All @@ -1504,15 +1533,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
// If shift is pressed and there is a selection we extend it using
// the selection mode (expand the "end" selection point)
_terminal->SetSelectionEnd(terminalPosition, ConvertToInternalSelectionExpansion(mode));
_terminal->SetSelectionEnd(terminalPosition, mode);
selectionNeedsToBeCopied = true;
}
else if (mode != Core::SelectionExpansion::Char || shiftEnabled)
else if (mode != ::Terminal::SelectionExpansion::Char || shiftEnabled)
{
// If we are handling a double / triple-click or shift+single click
// we establish selection using the selected mode
// (expand both "start" and "end" selection points)
_terminal->MultiClickSelection(terminalPosition, ConvertToInternalSelectionExpansion(mode));
_terminal->MultiClickSelection(terminalPosition, mode);
selectionNeedsToBeCopied = true;
}

Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
Windows::Foundation::Collections::IVector<winrt::hstring> SelectedText(bool trimTrailingWhitespace) const;
void SetSelectionAnchor(til::point const& position);
void SetEndSelectionPoint(til::point const& position);
bool UpdateSelection(Core::SelectionDirection direction, Core::SelectionExpansion mode);

void Search(const winrt::hstring& text,
const bool goForward,
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalControl/ControlCore.idl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ namespace Microsoft.Terminal.Control

Boolean HasSelection { get; };
IVector<String> SelectedText(Boolean trimTrailingWhitespace);
Boolean UpdateSelection(Microsoft.Terminal.Core.SelectionDirection direction, Microsoft.Terminal.Core.SelectionExpansion mode);

String HoveredUriText { get; };
Windows.Foundation.IReference<Microsoft.Terminal.Core.Point> HoveredCell { get; };
Expand Down
5 changes: 0 additions & 5 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2577,9 +2577,4 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
return _core.ReadEntireBuffer();
}

bool TermControl::UpdateSelection(Core::SelectionDirection direction, Core::SelectionExpansion mode)
{
return _core.UpdateSelection(direction, mode);
}
}
1 change: 0 additions & 1 deletion src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation

hstring GetProfileName() const;

bool UpdateSelection(Core::SelectionDirection direction, Core::SelectionExpansion mode);
bool CopySelectionToClipboard(bool singleLine, const Windows::Foundation::IReference<CopyFormat>& formats);
void PasteTextFromClipboard();
void Close();
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ namespace Microsoft.Terminal.Control
// We expose this and ConnectionState here so that it might eventually be data bound.
event Windows.Foundation.TypedEventHandler<Object, IInspectable> ConnectionStateChanged;

Boolean UpdateSelection(Microsoft.Terminal.Core.SelectionDirection direction, Microsoft.Terminal.Core.SelectionExpansion mode);
Boolean CopySelectionToClipboard(Boolean singleLine, Windows.Foundation.IReference<CopyFormat> formats);
void PasteTextFromClipboard();
void ClearBuffer(ClearBufferType clearType);
Expand Down
18 changes: 0 additions & 18 deletions src/cascadia/TerminalCore/ICoreSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,6 @@ import "..\ICoreAppearance.idl";

namespace Microsoft.Terminal.Core
{
enum SelectionDirection
{
None = 0,
Left,
Right,
Up,
Down,
};

enum SelectionExpansion
{
Char,
Word,
Line, // Mouse selection only! Not a setting!
Viewport,
Buffer
};

interface ICoreSettings requires ICoreAppearance
{
// TODO:MSFT:20642297 - define a sentinel for Infinite Scrollback
Expand Down
Loading

0 comments on commit 118d1cd

Please sign in to comment.