Skip to content

Commit

Permalink
PRE-MERGE #13765 Introduce ExpandSelectionToWord action
Browse files Browse the repository at this point in the history
  • Loading branch information
DHowett committed Aug 23, 2022
2 parents e9663eb + 9fd779a commit 4383741
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 75 deletions.
1 change: 1 addition & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@
"commandPalette",
"copy",
"duplicateTab",
"expandSelectionToWord",
"exportBuffer",
"find",
"findMatch",
Expand Down
10 changes: 10 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,4 +1122,14 @@ namespace winrt::TerminalApp::implementation
args.Handled(handled);
}
}

void TerminalPage::_HandleExpandSelectionToWord(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
if (const auto& control{ _GetActiveControl() })
{
const auto handled = control.ExpandSelectionToWord();
args.Handled(handled);
}
}
}
11 changes: 11 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return false;
}

bool ControlCore::ExpandSelectionToWord()
{
if (_terminal->IsSelectionActive())
{
_terminal->ExpandSelectionToWord();
_updateSelectionUI();
return true;
}
return false;
}

// Method Description:
// - Pre-process text pasted (presumably from the clipboard)
// before sending it over the terminal's connection.
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void ToggleMarkMode();
Control::SelectionInteractionMode SelectionMode() const;
bool SwitchSelectionEndpoint();
bool ExpandSelectionToWord();
bool TryMarkModeKeybinding(const WORD vkey,
const ::Microsoft::Terminal::Core::ControlKeyStates modifiers);

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlCore.idl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ namespace Microsoft.Terminal.Control
Boolean ToggleBlockSelection();
void ToggleMarkMode();
Boolean SwitchSelectionEndpoint();
Boolean ExpandSelectionToWord();
void ClearBuffer(ClearBufferType clearType);

void SetHoveredCell(Microsoft.Terminal.Core.Point terminalPosition);
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _core.SwitchSelectionEndpoint();
}

bool TermControl::ExpandSelectionToWord()
{
return _core.ExpandSelectionToWord();
}

void TermControl::Close()
{
if (!_IsClosing())
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
bool ToggleBlockSelection();
void ToggleMarkMode();
bool SwitchSelectionEndpoint();
bool ExpandSelectionToWord();
void Close();
Windows::Foundation::Size CharacterDimensions() const;
Windows::Foundation::Size MinimumSize();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace Microsoft.Terminal.Control
Boolean ToggleBlockSelection();
void ToggleMarkMode();
Boolean SwitchSelectionEndpoint();
Boolean ExpandSelectionToWord();
void ClearBuffer(ClearBufferType clearType);
void Close();
Windows.Foundation.Size CharacterDimensions { get; };
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class Microsoft::Terminal::Core::Terminal final :
void SelectAll();
SelectionInteractionMode SelectionMode() const noexcept;
void SwitchSelectionEndpoint();
void ExpandSelectionToWord();
void ToggleMarkMode();
void SelectHyperlink(const SearchDirection dir);
bool IsTargetingUrl() const noexcept;
Expand Down
10 changes: 10 additions & 0 deletions src/cascadia/TerminalCore/TerminalSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,16 @@ void Terminal::SwitchSelectionEndpoint()
}
}

void Terminal::ExpandSelectionToWord()
{
if (IsSelectionActive())
{
const auto& buffer = _activeBuffer();
_selection->start = buffer.GetWordStart(_selection->start, _wordDelimiters);
_selection->end = buffer.GetWordEnd(_selection->end, _wordDelimiters);
}
}

// Method Description:
// - selects the next/previous hyperlink, if one is available
// Arguments:
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static constexpr std::string_view SelectAllKey{ "selectAll" };
static constexpr std::string_view MarkModeKey{ "markMode" };
static constexpr std::string_view ToggleBlockSelectionKey{ "toggleBlockSelection" };
static constexpr std::string_view SwitchSelectionEndpointKey{ "switchSelectionEndpoint" };
static constexpr std::string_view ExpandSelectionToWordKey{ "expandSelectionToWord" };

static constexpr std::string_view ActionKey{ "action" };

Expand Down Expand Up @@ -402,6 +403,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{ ShortcutAction::MarkMode, RS_(L"MarkModeCommandKey") },
{ ShortcutAction::ToggleBlockSelection, RS_(L"ToggleBlockSelectionCommandKey") },
{ ShortcutAction::SwitchSelectionEndpoint, RS_(L"SwitchSelectionEndpointCommandKey") },
{ ShortcutAction::ExpandSelectionToWord, RS_(L"ExpandSelectionToWordCommandKey") },
};
}();

Expand Down
149 changes: 75 additions & 74 deletions src/cascadia/TerminalSettingsModel/AllShortcutActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,80 +23,81 @@
// each action. This is _NOT_ something that should be used when any individual
// case should be customized.

#define ALL_SHORTCUT_ACTIONS \
ON_ALL_ACTIONS(CopyText) \
ON_ALL_ACTIONS(PasteText) \
ON_ALL_ACTIONS(OpenNewTabDropdown) \
ON_ALL_ACTIONS(DuplicateTab) \
ON_ALL_ACTIONS(NewTab) \
ON_ALL_ACTIONS(CloseWindow) \
ON_ALL_ACTIONS(CloseTab) \
ON_ALL_ACTIONS(ClosePane) \
ON_ALL_ACTIONS(NextTab) \
ON_ALL_ACTIONS(PrevTab) \
ON_ALL_ACTIONS(SendInput) \
ON_ALL_ACTIONS(SplitPane) \
ON_ALL_ACTIONS(ToggleSplitOrientation) \
ON_ALL_ACTIONS(TogglePaneZoom) \
ON_ALL_ACTIONS(SwitchToTab) \
ON_ALL_ACTIONS(AdjustFontSize) \
ON_ALL_ACTIONS(ResetFontSize) \
ON_ALL_ACTIONS(ScrollUp) \
ON_ALL_ACTIONS(ScrollDown) \
ON_ALL_ACTIONS(ScrollUpPage) \
ON_ALL_ACTIONS(ScrollDownPage) \
ON_ALL_ACTIONS(ScrollToTop) \
ON_ALL_ACTIONS(ScrollToBottom) \
ON_ALL_ACTIONS(ScrollToMark) \
ON_ALL_ACTIONS(AddMark) \
ON_ALL_ACTIONS(ClearMark) \
ON_ALL_ACTIONS(ClearAllMarks) \
ON_ALL_ACTIONS(ResizePane) \
ON_ALL_ACTIONS(MoveFocus) \
ON_ALL_ACTIONS(MovePane) \
ON_ALL_ACTIONS(SwapPane) \
ON_ALL_ACTIONS(Find) \
ON_ALL_ACTIONS(ToggleShaderEffects) \
ON_ALL_ACTIONS(ToggleFocusMode) \
ON_ALL_ACTIONS(ToggleFullscreen) \
ON_ALL_ACTIONS(ToggleAlwaysOnTop) \
ON_ALL_ACTIONS(OpenSettings) \
ON_ALL_ACTIONS(SetFocusMode) \
ON_ALL_ACTIONS(SetFullScreen) \
ON_ALL_ACTIONS(SetMaximized) \
ON_ALL_ACTIONS(SetColorScheme) \
ON_ALL_ACTIONS(SetTabColor) \
ON_ALL_ACTIONS(OpenTabColorPicker) \
ON_ALL_ACTIONS(RenameTab) \
ON_ALL_ACTIONS(OpenTabRenamer) \
ON_ALL_ACTIONS(ExecuteCommandline) \
ON_ALL_ACTIONS(ToggleCommandPalette) \
ON_ALL_ACTIONS(CloseOtherTabs) \
ON_ALL_ACTIONS(CloseTabsAfter) \
ON_ALL_ACTIONS(TabSearch) \
ON_ALL_ACTIONS(MoveTab) \
ON_ALL_ACTIONS(BreakIntoDebugger) \
ON_ALL_ACTIONS(TogglePaneReadOnly) \
ON_ALL_ACTIONS(FindMatch) \
ON_ALL_ACTIONS(NewWindow) \
ON_ALL_ACTIONS(IdentifyWindow) \
ON_ALL_ACTIONS(IdentifyWindows) \
ON_ALL_ACTIONS(RenameWindow) \
ON_ALL_ACTIONS(OpenWindowRenamer) \
ON_ALL_ACTIONS(GlobalSummon) \
ON_ALL_ACTIONS(QuakeMode) \
ON_ALL_ACTIONS(FocusPane) \
ON_ALL_ACTIONS(OpenSystemMenu) \
ON_ALL_ACTIONS(ExportBuffer) \
ON_ALL_ACTIONS(ClearBuffer) \
ON_ALL_ACTIONS(MultipleActions) \
ON_ALL_ACTIONS(Quit) \
ON_ALL_ACTIONS(AdjustOpacity) \
ON_ALL_ACTIONS(RestoreLastClosed) \
ON_ALL_ACTIONS(SelectAll) \
ON_ALL_ACTIONS(MarkMode) \
ON_ALL_ACTIONS(ToggleBlockSelection) \
ON_ALL_ACTIONS(SwitchSelectionEndpoint)
#define ALL_SHORTCUT_ACTIONS \
ON_ALL_ACTIONS(CopyText) \
ON_ALL_ACTIONS(PasteText) \
ON_ALL_ACTIONS(OpenNewTabDropdown) \
ON_ALL_ACTIONS(DuplicateTab) \
ON_ALL_ACTIONS(NewTab) \
ON_ALL_ACTIONS(CloseWindow) \
ON_ALL_ACTIONS(CloseTab) \
ON_ALL_ACTIONS(ClosePane) \
ON_ALL_ACTIONS(NextTab) \
ON_ALL_ACTIONS(PrevTab) \
ON_ALL_ACTIONS(SendInput) \
ON_ALL_ACTIONS(SplitPane) \
ON_ALL_ACTIONS(ToggleSplitOrientation) \
ON_ALL_ACTIONS(TogglePaneZoom) \
ON_ALL_ACTIONS(SwitchToTab) \
ON_ALL_ACTIONS(AdjustFontSize) \
ON_ALL_ACTIONS(ResetFontSize) \
ON_ALL_ACTIONS(ScrollUp) \
ON_ALL_ACTIONS(ScrollDown) \
ON_ALL_ACTIONS(ScrollUpPage) \
ON_ALL_ACTIONS(ScrollDownPage) \
ON_ALL_ACTIONS(ScrollToTop) \
ON_ALL_ACTIONS(ScrollToBottom) \
ON_ALL_ACTIONS(ScrollToMark) \
ON_ALL_ACTIONS(AddMark) \
ON_ALL_ACTIONS(ClearMark) \
ON_ALL_ACTIONS(ClearAllMarks) \
ON_ALL_ACTIONS(ResizePane) \
ON_ALL_ACTIONS(MoveFocus) \
ON_ALL_ACTIONS(MovePane) \
ON_ALL_ACTIONS(SwapPane) \
ON_ALL_ACTIONS(Find) \
ON_ALL_ACTIONS(ToggleShaderEffects) \
ON_ALL_ACTIONS(ToggleFocusMode) \
ON_ALL_ACTIONS(ToggleFullscreen) \
ON_ALL_ACTIONS(ToggleAlwaysOnTop) \
ON_ALL_ACTIONS(OpenSettings) \
ON_ALL_ACTIONS(SetFocusMode) \
ON_ALL_ACTIONS(SetFullScreen) \
ON_ALL_ACTIONS(SetMaximized) \
ON_ALL_ACTIONS(SetColorScheme) \
ON_ALL_ACTIONS(SetTabColor) \
ON_ALL_ACTIONS(OpenTabColorPicker) \
ON_ALL_ACTIONS(RenameTab) \
ON_ALL_ACTIONS(OpenTabRenamer) \
ON_ALL_ACTIONS(ExecuteCommandline) \
ON_ALL_ACTIONS(ToggleCommandPalette) \
ON_ALL_ACTIONS(CloseOtherTabs) \
ON_ALL_ACTIONS(CloseTabsAfter) \
ON_ALL_ACTIONS(TabSearch) \
ON_ALL_ACTIONS(MoveTab) \
ON_ALL_ACTIONS(BreakIntoDebugger) \
ON_ALL_ACTIONS(TogglePaneReadOnly) \
ON_ALL_ACTIONS(FindMatch) \
ON_ALL_ACTIONS(NewWindow) \
ON_ALL_ACTIONS(IdentifyWindow) \
ON_ALL_ACTIONS(IdentifyWindows) \
ON_ALL_ACTIONS(RenameWindow) \
ON_ALL_ACTIONS(OpenWindowRenamer) \
ON_ALL_ACTIONS(GlobalSummon) \
ON_ALL_ACTIONS(QuakeMode) \
ON_ALL_ACTIONS(FocusPane) \
ON_ALL_ACTIONS(OpenSystemMenu) \
ON_ALL_ACTIONS(ExportBuffer) \
ON_ALL_ACTIONS(ClearBuffer) \
ON_ALL_ACTIONS(MultipleActions) \
ON_ALL_ACTIONS(Quit) \
ON_ALL_ACTIONS(AdjustOpacity) \
ON_ALL_ACTIONS(RestoreLastClosed) \
ON_ALL_ACTIONS(SelectAll) \
ON_ALL_ACTIONS(MarkMode) \
ON_ALL_ACTIONS(ToggleBlockSelection) \
ON_ALL_ACTIONS(SwitchSelectionEndpoint) \
ON_ALL_ACTIONS(ExpandSelectionToWord)

#define ALL_SHORTCUT_ACTIONS_WITH_ARGS \
ON_ALL_ACTIONS_WITH_ARGS(AdjustFontSize) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,4 +567,7 @@
<data name="SwitchSelectionEndpointCommandKey" xml:space="preserve">
<value>Switch selection endpoint</value>
</data>
</root>
<data name="ExpandSelectionToWordCommandKey" xml:space="preserve">
<value>Expand selection to word</value>
</data>
</root>
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
{ "command": "markMode", "keys": "ctrl+shift+m" },
{ "command": "toggleBlockSelection" },
{ "command": "switchSelectionEndpoint" },
{ "command": "expandSelectionToWord" },

// Scrollback
{ "command": "scrollDown", "keys": "ctrl+shift+down" },
Expand Down

0 comments on commit 4383741

Please sign in to comment.