From 07dc0601f9c0b5394e23f16cb86239bf225be7cc Mon Sep 17 00:00:00 2001 From: Schuyler Rosefield Date: Thu, 26 Aug 2021 13:58:56 -0400 Subject: [PATCH] Add first pane movement for MoveFocus/SwapPane. (#11044) This commit adds the ability to target the first pane in the tree, always. I wasn't able to find an existing issue for this, it is just a personal feature for me. I won't be heartbroken if it does not get merged. As motivation, I frequently have setups where the thing I am primarily working on is a large pane on the left and everything else is in smaller panes positioned elsewhere. I like to have one hotkey where I can go to any pane and then make it the "primary" pane if I am changing what I am working on or need to focus on another set of code/documentation/etc. ## Validation Steps Performed Confirmed that the move focus and swap pane variants both affect the correct pane. --- doc/cascadia/profiles.schema.json | 3 +- .../TerminalApp/AppCommandlineArgs.cpp | 2 ++ src/cascadia/TerminalApp/Pane.cpp | 21 +++++++++++++ .../TerminalSettingsModel/ActionArgs.cpp | 6 ++++ .../TerminalSettingsModel/ActionArgs.idl | 3 +- .../Resources/en-US/Resources.resw | 30 +++++++++++-------- .../TerminalSettingsSerializationHelpers.h | 3 +- .../TerminalSettingsModel/defaults.json | 2 ++ 8 files changed, 55 insertions(+), 15 deletions(-) diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 13e3a2b0c..9d5bd5456 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -299,7 +299,8 @@ "down", "previous", "nextInOrder", - "previousInOrder" + "previousInOrder", + "first" ], "type": "string" }, diff --git a/src/cascadia/TerminalApp/AppCommandlineArgs.cpp b/src/cascadia/TerminalApp/AppCommandlineArgs.cpp index a2da96205..69f609ea8 100644 --- a/src/cascadia/TerminalApp/AppCommandlineArgs.cpp +++ b/src/cascadia/TerminalApp/AppCommandlineArgs.cpp @@ -399,8 +399,10 @@ static const std::map focusDirectionMap = { { "right", FocusDirection::Right }, { "up", FocusDirection::Up }, { "down", FocusDirection::Down }, + { "previous", FocusDirection::Previous }, { "nextInOrder", FocusDirection::NextInOrder }, { "previousInOrder", FocusDirection::PreviousInOrder }, + { "first", FocusDirection::First }, }; // Method Description: diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index 90ad97683..28646b11b 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -251,6 +251,27 @@ std::shared_ptr Pane::NavigateDirection(const std::shared_ptr source return PreviousPane(sourcePane); } + if (direction == FocusDirection::First) + { + std::shared_ptr firstPane = nullptr; + WalkTree([&](auto p) { + if (p->_IsLeaf()) + { + firstPane = p; + return true; + } + + return false; + }); + + // Don't need to do any movement if we are the source and target pane. + if (firstPane == sourcePane) + { + return nullptr; + } + return firstPane; + } + // We are left with directional traversal now // If the focus direction does not match the split direction, the source pane // and its neighbor must necessarily be contained within the same child. diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp index bd49bf43d..fab78a2f1 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp @@ -296,7 +296,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation return RS_(L"MoveFocusNextInOrder"); case FocusDirection::PreviousInOrder: return RS_(L"MoveFocusPreviousInOrder"); + case FocusDirection::First: + return RS_(L"MoveFocusFirstPane"); } + return winrt::hstring{ fmt::format(std::wstring_view(RS_(L"MoveFocusWithArgCommandKey")), directionString) @@ -326,7 +329,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation return RS_(L"SwapPaneNextInOrder"); case FocusDirection::PreviousInOrder: return RS_(L"SwapPanePreviousInOrder"); + case FocusDirection::First: + return RS_(L"SwapPaneFirstPane"); } + return winrt::hstring{ fmt::format(std::wstring_view(RS_(L"SwapPaneWithArgCommandKey")), directionString) diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.idl b/src/cascadia/TerminalSettingsModel/ActionArgs.idl index 2369a8135..202262b19 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.idl +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.idl @@ -35,7 +35,8 @@ namespace Microsoft.Terminal.Settings.Model Down, Previous, PreviousInOrder, - NextInOrder + NextInOrder, + First }; enum SplitState diff --git a/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw index 0f2f88353..9ab450753 100644 --- a/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw @@ -246,6 +246,15 @@ Move focus to the last used pane + + Move focus to the next pane in order + + + Move focus to the previous pane in order + + + Move focus to the first pane + Swap pane @@ -256,6 +265,15 @@ Swap panes with the last used pane + + Swap panes with the next pane in order + + + Swap panes with the previous pane in order + + + Swap panes with the first pane + New tab @@ -436,18 +454,6 @@ Windows Console Host Name describing the usage of the classic windows console as the terminal UI. (`conhost.exe`) - - Move focus to the next pane in order - - - Move focus to the previous pane in order - - - Swap panes with the next pane in order - - - Swap panes with the previous pane in order - Minimize current window to tray diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h index abfdebf21..188587f57 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h @@ -337,7 +337,7 @@ struct ::Microsoft::Terminal::Settings::Model::JsonUtils::ConversionTrait<::winr // Possible FocusDirection values JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::FocusDirection) { - JSON_MAPPINGS(7) = { + JSON_MAPPINGS(8) = { pair_type{ "left", ValueType::Left }, pair_type{ "right", ValueType::Right }, pair_type{ "up", ValueType::Up }, @@ -345,6 +345,7 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::FocusDirection) pair_type{ "previous", ValueType::Previous }, pair_type{ "previousInOrder", ValueType::PreviousInOrder }, pair_type{ "nextInOrder", ValueType::NextInOrder }, + pair_type{ "first", ValueType::First }, }; }; diff --git a/src/cascadia/TerminalSettingsModel/defaults.json b/src/cascadia/TerminalSettingsModel/defaults.json index 940f9a5ae..ee1cdeb76 100644 --- a/src/cascadia/TerminalSettingsModel/defaults.json +++ b/src/cascadia/TerminalSettingsModel/defaults.json @@ -348,6 +348,7 @@ { "command": { "action": "moveFocus", "direction": "previous" }, "keys": "ctrl+alt+left"}, { "command": { "action": "moveFocus", "direction": "previousInOrder" } }, { "command": { "action": "moveFocus", "direction": "nextInOrder" } }, + { "command": { "action": "moveFocus", "direction": "first" } }, { "command": { "action": "swapPane", "direction": "down" } }, { "command": { "action": "swapPane", "direction": "left" } }, { "command": { "action": "swapPane", "direction": "right" } }, @@ -355,6 +356,7 @@ { "command": { "action": "swapPane", "direction": "previous"} }, { "command": { "action": "swapPane", "direction": "previousInOrder"} }, { "command": { "action": "swapPane", "direction": "nextInOrder"} }, + { "command": { "action": "swapPane", "direction": "first" } }, { "command": "togglePaneZoom" }, { "command": "toggleSplitOrientation" }, { "command": "toggleReadOnlyMode" },