From 118d1cdc023f33a06fb88e160d8f4defb5b14e39 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Thu, 16 Sep 2021 19:58:42 -0700 Subject: [PATCH] remove configurability --- doc/cascadia/profiles.schema.json | 44 +----- .../TerminalApp/AppActionHandlers.cpp | 15 -- src/cascadia/TerminalControl/ControlCore.cpp | 129 +++++++++++------- src/cascadia/TerminalControl/ControlCore.h | 1 - src/cascadia/TerminalControl/ControlCore.idl | 1 - src/cascadia/TerminalControl/TermControl.cpp | 5 - src/cascadia/TerminalControl/TermControl.h | 1 - src/cascadia/TerminalControl/TermControl.idl | 1 - src/cascadia/TerminalCore/ICoreSettings.idl | 18 --- src/cascadia/TerminalCore/Terminal.hpp | 52 ++++--- .../TerminalCore/TerminalSelection.cpp | 62 ++++----- .../TerminalCore/terminalrenderdata.cpp | 2 +- .../TerminalSettingsModel/ActionAndArgs.cpp | 1 - .../TerminalSettingsModel/ActionArgs.cpp | 6 - .../TerminalSettingsModel/ActionArgs.h | 62 --------- .../TerminalSettingsModel/ActionArgs.idl | 6 - .../AllShortcutActions.h | 6 +- .../TerminalSettingsSerializationHelpers.h | 20 --- .../TerminalSettingsModel/defaults.json | 14 -- src/types/UiaTextRangeBase.cpp | 2 +- 20 files changed, 139 insertions(+), 309 deletions(-) diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 715ddb4d9..6a2c91479 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -304,7 +304,6 @@ "toggleSplitOrientation", "toggleReadOnlyMode", "toggleShaderEffects", - "updateSelection", "wt", "quit", "unbound" @@ -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", @@ -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": [ @@ -888,7 +847,7 @@ } ], "required": [ "actions" ] - }, + }, "CommandPaletteAction": { "description": "Arguments for a commandPalette action", "allOf": [ @@ -1107,7 +1066,6 @@ { "$ref": "#/definitions/FocusPaneAction" }, { "$ref": "#/definitions/GlobalSummonAction" }, { "$ref": "#/definitions/QuakeModeAction" }, - { "$ref": "#/definitions/UpdateSelectionAction" }, { "type": "null" } ] }, diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 6dd3c8768..1ef4c0c8a 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -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()) - { - if (const auto termControl{ _GetActiveControl() }) - { - args.Handled(termControl.UpdateSelection(realArgs.Direction(), realArgs.Mode())); - } - } - } - } } diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 9099a5768..ca0dd49d6 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -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 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> 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 @@ -393,21 +427,28 @@ 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()) { @@ -415,6 +456,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation _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; @@ -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) @@ -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 @@ -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; } diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index 3eedcad93..a04032ef7 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -130,7 +130,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation Windows::Foundation::Collections::IVector 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, diff --git a/src/cascadia/TerminalControl/ControlCore.idl b/src/cascadia/TerminalControl/ControlCore.idl index 467e30bbb..84cb83e80 100644 --- a/src/cascadia/TerminalControl/ControlCore.idl +++ b/src/cascadia/TerminalControl/ControlCore.idl @@ -80,7 +80,6 @@ namespace Microsoft.Terminal.Control Boolean HasSelection { get; }; IVector SelectedText(Boolean trimTrailingWhitespace); - Boolean UpdateSelection(Microsoft.Terminal.Core.SelectionDirection direction, Microsoft.Terminal.Core.SelectionExpansion mode); String HoveredUriText { get; }; Windows.Foundation.IReference HoveredCell { get; }; diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 7686cd909..115f9afc5 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -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); - } } diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index fbd573bae..9d0f22e33 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -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& formats); void PasteTextFromClipboard(); void Close(); diff --git a/src/cascadia/TerminalControl/TermControl.idl b/src/cascadia/TerminalControl/TermControl.idl index 9b5b03d1a..26db0862c 100644 --- a/src/cascadia/TerminalControl/TermControl.idl +++ b/src/cascadia/TerminalControl/TermControl.idl @@ -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 ConnectionStateChanged; - Boolean UpdateSelection(Microsoft.Terminal.Core.SelectionDirection direction, Microsoft.Terminal.Core.SelectionExpansion mode); Boolean CopySelectionToClipboard(Boolean singleLine, Windows.Foundation.IReference formats); void PasteTextFromClipboard(); void ClearBuffer(ClearBufferType clearType); diff --git a/src/cascadia/TerminalCore/ICoreSettings.idl b/src/cascadia/TerminalCore/ICoreSettings.idl index e03569414..dd0b4939b 100644 --- a/src/cascadia/TerminalCore/ICoreSettings.idl +++ b/src/cascadia/TerminalCore/ICoreSettings.idl @@ -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 diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index e066da3da..bc51241b9 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -35,26 +35,6 @@ namespace winrt::Microsoft::Terminal::Core namespace Microsoft::Terminal::Core { class Terminal; - - // TODO GH#6999: We need to convert winrt::Microsoft::Terminal::Core::SelectionDirection/Expansion - // into an equivalent enum class because PublicTerminalCore doesn't consume winrt. Once we introduce - // an interactivity layer, we'll be able to remove this duplicate enum and directly use the winrt enums. - enum class InternalSelectionDirection - { - Left, - Right, - Up, - Down - }; - - enum class InternalSelectionExpansion - { - Char, - Word, - Line, // Mouse selection only! Not a setting! - Viewport, - Buffer - }; } // fwdecl unittest classes @@ -247,11 +227,27 @@ public: #pragma region TextSelection // These methods are defined in TerminalSelection.cpp - void MultiClickSelection(const COORD viewportPos, InternalSelectionExpansion expansionMode); + enum class SelectionDirection + { + Left, + Right, + Up, + Down + }; + + enum class SelectionExpansion + { + Char, + Word, + Line, // Mouse selection only! Not a setting! + Viewport, + Buffer + }; + void MultiClickSelection(const COORD viewportPos, SelectionExpansion expansionMode); void SetSelectionAnchor(const COORD position); - void SetSelectionEnd(const COORD position, std::optional newExpansionMode = std::nullopt); + void SetSelectionEnd(const COORD position, std::optional newExpansionMode = std::nullopt); void SetBlockSelection(const bool isEnabled) noexcept; - void UpdateSelection(InternalSelectionDirection direction, InternalSelectionExpansion mode); + void UpdateSelection(SelectionDirection direction, SelectionExpansion mode); const TextBuffer::TextAndColor RetrieveSelectedTextFromBuffer(bool trimTrailingWhitespace); #pragma endregion @@ -323,7 +319,7 @@ private: std::optional _selection; bool _blockSelection; std::wstring _wordDelimiters; - InternalSelectionExpansion _multiClickSelectionMode; + SelectionExpansion _multiClickSelectionMode; #pragma endregion // TODO: These members are not shared by an alt-buffer. They should be @@ -390,10 +386,10 @@ private: std::tuple _PivotSelection(const COORD targetPos) const; std::pair _ExpandSelectionAnchors(std::pair anchors) const; COORD _ConvertToBufferCell(const COORD viewportPos) const; - void _MoveByChar(InternalSelectionDirection direction, COORD& pos); - void _MoveByWord(InternalSelectionDirection direction, COORD& pos); - void _MoveByViewport(InternalSelectionDirection direction, COORD& pos); - void _MoveByBuffer(InternalSelectionDirection direction, COORD& pos); + void _MoveByChar(SelectionDirection direction, COORD& pos); + void _MoveByWord(SelectionDirection direction, COORD& pos); + void _MoveByViewport(SelectionDirection direction, COORD& pos); + void _MoveByBuffer(SelectionDirection direction, COORD& pos); #pragma endregion Microsoft::Console::VirtualTerminal::SgrStack _sgrStack; diff --git a/src/cascadia/TerminalCore/TerminalSelection.cpp b/src/cascadia/TerminalCore/TerminalSelection.cpp index f49916a66..0c15894ea 100644 --- a/src/cascadia/TerminalCore/TerminalSelection.cpp +++ b/src/cascadia/TerminalCore/TerminalSelection.cpp @@ -104,7 +104,7 @@ const bool Terminal::IsBlockSelection() const noexcept // Arguments: // - viewportPos: the (x,y) coordinate on the visible viewport // - expansionMode: the SelectionExpansion to dictate the boundaries of the selection anchors -void Terminal::MultiClickSelection(const COORD viewportPos, InternalSelectionExpansion expansionMode) +void Terminal::MultiClickSelection(const COORD viewportPos, SelectionExpansion expansionMode) { // set the selection pivot to expand the selection using SetSelectionEnd() _selection = SelectionAnchors{}; @@ -127,7 +127,7 @@ void Terminal::SetSelectionAnchor(const COORD viewportPos) _selection = SelectionAnchors{}; _selection->pivot = _ConvertToBufferCell(viewportPos); - _multiClickSelectionMode = InternalSelectionExpansion::Char; + _multiClickSelectionMode = SelectionExpansion::Char; SetSelectionEnd(viewportPos); _selection->start = _selection->pivot; @@ -139,7 +139,7 @@ void Terminal::SetSelectionAnchor(const COORD viewportPos) // Arguments: // - viewportPos: the (x,y) coordinate on the visible viewport // - newExpansionMode: overwrites the _multiClickSelectionMode for this function call. Used for ShiftClick -void Terminal::SetSelectionEnd(const COORD viewportPos, std::optional newExpansionMode) +void Terminal::SetSelectionEnd(const COORD viewportPos, std::optional newExpansionMode) { if (!_selection.has_value()) { @@ -216,15 +216,15 @@ std::pair Terminal::_ExpandSelectionAnchors(std::pairGetSize(); switch (_multiClickSelectionMode) { - case InternalSelectionExpansion::Line: + case SelectionExpansion::Line: start = { bufferSize.Left(), start.Y }; end = { bufferSize.RightInclusive(), end.Y }; break; - case InternalSelectionExpansion::Word: + case SelectionExpansion::Word: start = _buffer->GetWordStart(start, _wordDelimiters); end = _buffer->GetWordEnd(end, _wordDelimiters); break; - case InternalSelectionExpansion::Char: + case SelectionExpansion::Char: default: // no expansion is necessary break; @@ -241,7 +241,7 @@ void Terminal::SetBlockSelection(const bool isEnabled) noexcept _blockSelection = isEnabled; } -void Terminal::UpdateSelection(InternalSelectionDirection direction, InternalSelectionExpansion mode) +void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion mode) { // 1. Figure out which endpoint to update // One of the endpoints is the pivot, signifying that the other endpoint is the one we want to move. @@ -251,16 +251,16 @@ void Terminal::UpdateSelection(InternalSelectionDirection direction, InternalSel // 2. Perform the movement switch (mode) { - case InternalSelectionExpansion::Char: + case SelectionExpansion::Char: _MoveByChar(direction, targetPos); break; - case InternalSelectionExpansion::Word: + case SelectionExpansion::Word: _MoveByWord(direction, targetPos); break; - case InternalSelectionExpansion::Viewport: + case SelectionExpansion::Viewport: _MoveByViewport(direction, targetPos); break; - case InternalSelectionExpansion::Buffer: + case SelectionExpansion::Buffer: _MoveByBuffer(direction, targetPos); break; } @@ -287,25 +287,25 @@ void Terminal::UpdateSelection(InternalSelectionDirection direction, InternalSel } } -void Terminal::_MoveByChar(InternalSelectionDirection direction, COORD& pos) +void Terminal::_MoveByChar(SelectionDirection direction, COORD& pos) { switch (direction) { - case InternalSelectionDirection::Left: + case SelectionDirection::Left: _buffer->GetSize().DecrementInBounds(pos); pos = _buffer->GetGlyphStart(pos); break; - case InternalSelectionDirection::Right: + case SelectionDirection::Right: _buffer->GetSize().IncrementInBounds(pos); pos = _buffer->GetGlyphEnd(pos); break; - case InternalSelectionDirection::Up: + case SelectionDirection::Up: { const auto bufferSize{ _buffer->GetSize() }; pos = { pos.X, std::clamp(base::ClampSub(pos.Y, 1).RawValue(), bufferSize.Top(), bufferSize.BottomInclusive()) }; break; } - case InternalSelectionDirection::Down: + case SelectionDirection::Down: { const auto bufferSize{ _buffer->GetSize() }; pos = { pos.X, std::clamp(base::ClampAdd(pos.Y, 1).RawValue(), bufferSize.Top(), bufferSize.BottomInclusive()) }; @@ -314,11 +314,11 @@ void Terminal::_MoveByChar(InternalSelectionDirection direction, COORD& pos) } } -void Terminal::_MoveByWord(InternalSelectionDirection direction, COORD& pos) +void Terminal::_MoveByWord(SelectionDirection direction, COORD& pos) { switch (direction) { - case InternalSelectionDirection::Left: + case SelectionDirection::Left: const auto wordStartPos{ _buffer->GetWordStart(pos, _wordDelimiters) }; if (_buffer->GetSize().CompareInBounds(_selection->pivot, pos) < 0) { @@ -339,7 +339,7 @@ void Terminal::_MoveByWord(InternalSelectionDirection direction, COORD& pos) pos = wordStartPos; } break; - case InternalSelectionDirection::Right: + case SelectionDirection::Right: const auto wordEndPos{ _buffer->GetWordEnd(pos, _wordDelimiters) }; if (_buffer->GetSize().CompareInBounds(pos, _selection->pivot) < 0) { @@ -360,36 +360,36 @@ void Terminal::_MoveByWord(InternalSelectionDirection direction, COORD& pos) pos = wordEndPos; } break; - case InternalSelectionDirection::Up: + case SelectionDirection::Up: _MoveByChar(direction, pos); pos = _buffer->GetWordStart(pos, _wordDelimiters); break; - case InternalSelectionDirection::Down: + case SelectionDirection::Down: _MoveByChar(direction, pos); pos = _buffer->GetWordEnd(pos, _wordDelimiters); break; } } -void Terminal::_MoveByViewport(InternalSelectionDirection direction, COORD& pos) +void Terminal::_MoveByViewport(SelectionDirection direction, COORD& pos) { const auto bufferSize{ _buffer->GetSize() }; switch (direction) { - case InternalSelectionDirection::Left: + case SelectionDirection::Left: pos = { bufferSize.Left(), pos.Y }; break; - case InternalSelectionDirection::Right: + case SelectionDirection::Right: pos = { bufferSize.RightInclusive(), pos.Y }; break; - case InternalSelectionDirection::Up: + case SelectionDirection::Up: { const auto viewportHeight{ _mutableViewport.Height() }; const auto newY{ base::ClampSub(pos.Y, viewportHeight) }; pos = newY < bufferSize.Top() ? bufferSize.Origin() : COORD{ pos.X, newY }; break; } - case InternalSelectionDirection::Down: + case SelectionDirection::Down: { const auto viewportHeight{ _mutableViewport.Height() }; const auto mutableBottom{ _mutableViewport.BottomInclusive() }; @@ -400,17 +400,17 @@ void Terminal::_MoveByViewport(InternalSelectionDirection direction, COORD& pos) } } -void Terminal::_MoveByBuffer(InternalSelectionDirection direction, COORD& pos) +void Terminal::_MoveByBuffer(SelectionDirection direction, COORD& pos) { const auto bufferSize{ _buffer->GetSize() }; switch (direction) { - case InternalSelectionDirection::Left: - case InternalSelectionDirection::Up: + case SelectionDirection::Left: + case SelectionDirection::Up: pos = bufferSize.Origin(); break; - case InternalSelectionDirection::Right: - case InternalSelectionDirection::Down: + case SelectionDirection::Right: + case SelectionDirection::Down: pos = { bufferSize.RightInclusive(), _mutableViewport.BottomInclusive() }; break; } diff --git a/src/cascadia/TerminalCore/terminalrenderdata.cpp b/src/cascadia/TerminalCore/terminalrenderdata.cpp index f919d06a1..6ccb5791d 100644 --- a/src/cascadia/TerminalCore/terminalrenderdata.cpp +++ b/src/cascadia/TerminalCore/terminalrenderdata.cpp @@ -206,7 +206,7 @@ void Terminal::SelectNewRegion(const COORD coordStart, const COORD coordEnd) realCoordEnd.Y -= gsl::narrow(_VisibleStartIndex()); SetSelectionAnchor(realCoordStart); - SetSelectionEnd(realCoordEnd, InternalSelectionExpansion::Char); + SetSelectionEnd(realCoordEnd, SelectionExpansion::Char); } const std::wstring_view Terminal::GetConsoleTitle() const noexcept diff --git a/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp b/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp index dbdcb1746..2ae6bb6da 100644 --- a/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp @@ -69,7 +69,6 @@ static constexpr std::string_view OpenSystemMenuKey{ "openSystemMenu" }; static constexpr std::string_view ClearBufferKey{ "clearBuffer" }; static constexpr std::string_view MultipleActionsKey{ "multipleActions" }; static constexpr std::string_view QuitKey{ "quit" }; -static constexpr std::string_view UpdateSelectionKey{ "updateSelection" }; static constexpr std::string_view ActionKey{ "action" }; diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp index cc052f901..dd30f3547 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp @@ -36,7 +36,6 @@ #include "FocusPaneArgs.g.cpp" #include "ClearBufferArgs.g.cpp" #include "MultipleActionsArgs.g.cpp" -#include "UpdateSelectionArgs.g.cpp" #include @@ -719,9 +718,4 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { return L""; } - - winrt::hstring UpdateSelectionArgs::GenerateName() const - { - return L""; - } } diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.h b/src/cascadia/TerminalSettingsModel/ActionArgs.h index d05c7f9cb..94f7cebea 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.h +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.h @@ -38,7 +38,6 @@ #include "FocusPaneArgs.g.h" #include "ClearBufferArgs.g.h" #include "MultipleActionsArgs.g.h" -#include "UpdateSelectionArgs.g.h" #include "../../cascadia/inc/cppwinrt_utils.h" #include "JsonUtils.h" @@ -1860,67 +1859,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation return ::Microsoft::Terminal::Settings::Model::HashUtils::HashProperty(_Actions); } }; - - struct UpdateSelectionArgs : public UpdateSelectionArgsT - { - UpdateSelectionArgs() = default; - ACTION_ARG(Core::SelectionDirection, Direction, Core::SelectionDirection::None); - ACTION_ARG(Core::SelectionExpansion, Mode, Core::SelectionExpansion::Char); - static constexpr std::string_view DirectionKey{ "direction" }; - static constexpr std::string_view ModeKey{ "mode" }; - - public: - hstring GenerateName() const; - - bool Equals(const IActionArgs& other) - { - auto otherAsUs = other.try_as(); - if (otherAsUs) - { - return otherAsUs->_Direction == _Direction && otherAsUs->_Mode == _Mode; - } - return false; - }; - static FromJsonResult FromJson(const Json::Value& json) - { - // LOAD BEARING: Not using make_self here _will_ break you in the future! - auto args = winrt::make_self(); - JsonUtils::GetValueForKey(json, DirectionKey, args->_Direction); - JsonUtils::GetValueForKey(json, ModeKey, args->_Mode); - if (args->Direction() == Core::SelectionDirection::None) - { - return { nullptr, { SettingsLoadWarnings::MissingRequiredParameter } }; - } - else - { - return { *args, {} }; - } - } - static Json::Value ToJson(const IActionArgs& val) - { - if (!val) - { - return {}; - } - Json::Value json{ Json::ValueType::objectValue }; - const auto args{ get_self(val) }; - JsonUtils::SetValueForKey(json, DirectionKey, args->_Direction); - JsonUtils::SetValueForKey(json, ModeKey, args->_Mode); - return json; - } - IActionArgs Copy() const - { - auto copy{ winrt::make_self() }; - copy->_Direction = _Direction; - copy->_Mode = _Mode; - return *copy; - } - size_t Hash() const - { - return ::Microsoft::Terminal::Settings::Model::HashUtils::HashProperty(_Direction, _Mode); - } - }; - } namespace winrt::Microsoft::Terminal::Settings::Model::factory_implementation diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.idl b/src/cascadia/TerminalSettingsModel/ActionArgs.idl index 5acf82fb0..21b1b4b0b 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.idl +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.idl @@ -323,10 +323,4 @@ namespace Microsoft.Terminal.Settings.Model MultipleActionsArgs(); Windows.Foundation.Collections.IVector Actions; }; - - [default_interface] runtimeclass UpdateSelectionArgs : IActionArgs - { - Microsoft.Terminal.Core.SelectionDirection Direction { get; }; - Microsoft.Terminal.Core.SelectionExpansion Mode { get; }; - }; } diff --git a/src/cascadia/TerminalSettingsModel/AllShortcutActions.h b/src/cascadia/TerminalSettingsModel/AllShortcutActions.h index 801e8ece9..aa06ae70c 100644 --- a/src/cascadia/TerminalSettingsModel/AllShortcutActions.h +++ b/src/cascadia/TerminalSettingsModel/AllShortcutActions.h @@ -82,8 +82,7 @@ ON_ALL_ACTIONS(OpenSystemMenu) \ ON_ALL_ACTIONS(ClearBuffer) \ ON_ALL_ACTIONS(MultipleActions) \ - ON_ALL_ACTIONS(Quit) \ - ON_ALL_ACTIONS(UpdateSelection) + ON_ALL_ACTIONS(Quit) #define ALL_SHORTCUT_ACTIONS_WITH_ARGS \ ON_ALL_ACTIONS_WITH_ARGS(AdjustFontSize) \ @@ -116,5 +115,4 @@ ON_ALL_ACTIONS_WITH_ARGS(ToggleCommandPalette) \ ON_ALL_ACTIONS_WITH_ARGS(FocusPane) \ ON_ALL_ACTIONS_WITH_ARGS(ClearBuffer) \ - ON_ALL_ACTIONS_WITH_ARGS(MultipleActions) \ - ON_ALL_ACTIONS_WITH_ARGS(UpdateSelection) + ON_ALL_ACTIONS_WITH_ARGS(MultipleActions) diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h index db96440a8..83c791f95 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h @@ -512,23 +512,3 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::InfoBarMessage) pair_type{ "keyboardServiceWarning", ValueType::KeyboardServiceWarning }, }; }; - -JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Core::SelectionDirection) -{ - static constexpr std::array mappings = { - pair_type{ "left", ValueType::Left }, - pair_type{ "right", ValueType::Right }, - pair_type{ "up", ValueType::Up }, - pair_type{ "down", ValueType::Down } - }; -}; - -JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Core::SelectionExpansion) -{ - static constexpr std::array mappings = { - pair_type{ "char", ValueType::Char }, - pair_type{ "word", ValueType::Word }, - pair_type{ "view", ValueType::Viewport }, - pair_type{ "buffer", ValueType::Buffer } - }; -}; diff --git a/src/cascadia/TerminalSettingsModel/defaults.json b/src/cascadia/TerminalSettingsModel/defaults.json index 3e34f6c2c..6261e743a 100644 --- a/src/cascadia/TerminalSettingsModel/defaults.json +++ b/src/cascadia/TerminalSettingsModel/defaults.json @@ -380,20 +380,6 @@ { "command": "paste", "keys": "ctrl+shift+v" }, { "command": "paste", "keys": "shift+insert" }, - // Keyboard Selection - { "command": {"action": "updateSelection", "direction": "left", "mode": "char" }, "keys": "shift+left" }, - { "command": {"action": "updateSelection", "direction": "right", "mode": "char" }, "keys": "shift+right" }, - { "command": {"action": "updateSelection", "direction": "up", "mode": "char" }, "keys": "shift+up" }, - { "command": {"action": "updateSelection", "direction": "down", "mode": "char" }, "keys": "shift+down" }, - { "command": {"action": "updateSelection", "direction": "left", "mode": "word" }, "keys": "ctrl+shift+left" }, - { "command": {"action": "updateSelection", "direction": "right", "mode": "word" }, "keys": "ctrl+shift+right" }, - { "command": {"action": "updateSelection", "direction": "left", "mode": "view" }, "keys": "shift+home" }, - { "command": {"action": "updateSelection", "direction": "right", "mode": "view" }, "keys": "shift+end" }, - { "command": {"action": "updateSelection", "direction": "up", "mode": "view" }, "keys": "shift+pgup" }, - { "command": {"action": "updateSelection", "direction": "down", "mode": "view" }, "keys": "shift+pgdn" }, - { "command": {"action": "updateSelection", "direction": "up", "mode": "buffer" }, "keys": "ctrl+shift+home" }, - { "command": {"action": "updateSelection", "direction": "down", "mode": "buffer" }, "keys": "ctrl+shift+end" }, - // Scrollback { "command": "scrollDown", "keys": "ctrl+shift+down" }, { "command": "scrollDownPage", "keys": "ctrl+shift+pgdn" }, diff --git a/src/types/UiaTextRangeBase.cpp b/src/types/UiaTextRangeBase.cpp index a38779be2..464dffa02 100644 --- a/src/types/UiaTextRangeBase.cpp +++ b/src/types/UiaTextRangeBase.cpp @@ -295,7 +295,7 @@ void UiaTextRangeBase::_expandToEnclosingUnit(TextUnit unit) if (unit == TextUnit_Character) { _start = buffer.GetGlyphStart(_start, documentEnd); - _end = buffer.GetGlyphEnd(_start, documentEnd, true); + _end = buffer.GetGlyphEnd(_start, true, documentEnd); } else if (unit <= TextUnit_Word) {