From c89089f1186196402e231de49042bd0397b04cd7 Mon Sep 17 00:00:00 2001 From: Schuyler Rosefield Date: Wed, 25 Aug 2021 21:48:07 -0400 Subject: [PATCH 1/4] add first pane movement. --- doc/cascadia/profiles.schema.json | 3 +- .../TerminalApp/AppCommandlineArgs.cpp | 2 + src/cascadia/TerminalApp/Pane.cpp | 21 ++++++ .../TerminalSettingsModel/ActionArgs.cpp | 64 +++++++++++-------- .../TerminalSettingsModel/ActionArgs.idl | 3 +- .../Resources/en-US/Resources.resw | 34 +++++----- .../TerminalSettingsSerializationHelpers.h | 3 +- .../TerminalSettingsModel/defaults.json | 2 + 8 files changed, 88 insertions(+), 44 deletions(-) diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 13e3a2b0cbb..9d5bd545686 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 a2da962056a..69f609ea8e5 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 27d866e0fc5..d68646bd527 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 bd49bf43d0f..0e434828e1a 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp @@ -273,10 +273,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation }; } - winrt::hstring MoveFocusArgs::GenerateName() const + std::pair GetFocusDirectionString(const FocusDirection& direction) { winrt::hstring directionString; - switch (FocusDirection()) + bool isTarget = false; + switch (direction) { case FocusDirection::Left: directionString = RS_(L"DirectionLeft"); @@ -291,12 +292,38 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation directionString = RS_(L"DirectionDown"); break; case FocusDirection::Previous: - return RS_(L"MoveFocusToLastUsedPane"); + directionString = RS_(L"LastUsedPane"); + isTarget = true; + break; case FocusDirection::NextInOrder: - return RS_(L"MoveFocusNextInOrder"); + directionString = RS_(L"NextPaneInOrder"); + isTarget = true; + break; case FocusDirection::PreviousInOrder: - return RS_(L"MoveFocusPreviousInOrder"); + directionString = RS_(L"PreviousPaneInOrder"); + isTarget = true; + break; + case FocusDirection::First: + directionString = RS_(L"FirstPane"); + isTarget = true; + break; + } + + return { directionString, isTarget }; + + } + + winrt::hstring MoveFocusArgs::GenerateName() const + { + auto [directionString, isTarget] = GetFocusDirectionString(FocusDirection()); + if (isTarget) + { + return winrt::hstring{ + fmt::format(std::wstring_view(RS_(L"MoveFocusWithTargetArgCommandKey")), + directionString) + }; } + return winrt::hstring{ fmt::format(std::wstring_view(RS_(L"MoveFocusWithArgCommandKey")), directionString) @@ -305,28 +332,15 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation winrt::hstring SwapPaneArgs::GenerateName() const { - winrt::hstring directionString; - switch (Direction()) + auto [directionString, isTarget] = GetFocusDirectionString(Direction()); + if (isTarget) { - case FocusDirection::Left: - directionString = RS_(L"DirectionLeft"); - break; - case FocusDirection::Right: - directionString = RS_(L"DirectionRight"); - break; - case FocusDirection::Up: - directionString = RS_(L"DirectionUp"); - break; - case FocusDirection::Down: - directionString = RS_(L"DirectionDown"); - break; - case FocusDirection::Previous: - return RS_(L"SwapPaneToLastUsedPane"); - case FocusDirection::NextInOrder: - return RS_(L"SwapPaneNextInOrder"); - case FocusDirection::PreviousInOrder: - return RS_(L"SwapPanePreviousInOrder"); + return winrt::hstring{ + fmt::format(std::wstring_view(RS_(L"SwapPaneWithTargetArgCommandKey")), + directionString) + }; } + 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 2369a813503..202262b1979 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 0f2f883535f..4190b0a26cb 100644 --- a/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw @@ -207,6 +207,18 @@ up + + first pane + + + next pane in order + + + previous pane in order + + + last used pane + previous @@ -243,8 +255,9 @@ Move focus {0} {0} will be replaced with one of the four directions "DirectionLeft", "DirectionRight", "DirectionUp", "DirectionDown" - - Move focus to the last used pane + + Move focus to the {0} + {0} will be replaced with one of "LastUsedPane", "NextPaneInOrder", "PreviousPaneInOrder", "FirstPane" Swap pane @@ -253,8 +266,9 @@ Swap pane {0} {0} will be replaced with one of the four directions "DirectionLeft", "DirectionRight", "DirectionUp", "DirectionDown" - - Swap panes with the last used pane + + Swap panes with the {0} + {0} will be replaced with one of "LastUsedPane", "NextPaneInOrder", "PreviousPaneInOrder", "FirstPane" New tab @@ -436,18 +450,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 abfdebf21c7..188587f5708 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 940f9a5aee8..ee1cdeb76eb 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" }, From 8fdc48b9918853033cf0b0e25398db4313cc96d2 Mon Sep 17 00:00:00 2001 From: Schuyler Rosefield Date: Wed, 25 Aug 2021 23:06:26 -0400 Subject: [PATCH 2/4] formatting --- src/cascadia/TerminalSettingsModel/ActionArgs.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp index 0e434828e1a..5374632313a 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp @@ -310,7 +310,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation } return { directionString, isTarget }; - } winrt::hstring MoveFocusArgs::GenerateName() const From ff452ec0e7602b45d7ad7e094511f4000d804786 Mon Sep 17 00:00:00 2001 From: Schuyler Rosefield Date: Thu, 26 Aug 2021 10:20:01 -0400 Subject: [PATCH 3/4] Revert to having localization per action since english sentence order cannot be assumed everywhere. --- .../TerminalSettingsModel/ActionArgs.cpp | 63 +++++++++---------- .../Resources/en-US/Resources.resw | 28 +++++++-- 2 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp index 5374632313a..37625d1c2df 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp @@ -273,11 +273,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation }; } - std::pair GetFocusDirectionString(const FocusDirection& direction) + winrt::hstring MoveFocusArgs::GenerateName() const { winrt::hstring directionString; - bool isTarget = false; - switch (direction) + switch (FocusDirection()) { case FocusDirection::Left: directionString = RS_(L"DirectionLeft"); @@ -292,35 +291,13 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation directionString = RS_(L"DirectionDown"); break; case FocusDirection::Previous: - directionString = RS_(L"LastUsedPane"); - isTarget = true; - break; + return RS_(L"MoveFocusLastUsedPane"); case FocusDirection::NextInOrder: - directionString = RS_(L"NextPaneInOrder"); - isTarget = true; - break; + return RS_(L"MoveFocusNextPaneInOrder"); case FocusDirection::PreviousInOrder: - directionString = RS_(L"PreviousPaneInOrder"); - isTarget = true; - break; + return RS_(L"MoveFocusPreviousPaneInOrder"); case FocusDirection::First: - directionString = RS_(L"FirstPane"); - isTarget = true; - break; - } - - return { directionString, isTarget }; - } - - winrt::hstring MoveFocusArgs::GenerateName() const - { - auto [directionString, isTarget] = GetFocusDirectionString(FocusDirection()); - if (isTarget) - { - return winrt::hstring{ - fmt::format(std::wstring_view(RS_(L"MoveFocusWithTargetArgCommandKey")), - directionString) - }; + return RS_(L"MoveFocusFirstPane"); } return winrt::hstring{ @@ -331,13 +308,29 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation winrt::hstring SwapPaneArgs::GenerateName() const { - auto [directionString, isTarget] = GetFocusDirectionString(Direction()); - if (isTarget) + winrt::hstring directionString; + switch (Direction()) { - return winrt::hstring{ - fmt::format(std::wstring_view(RS_(L"SwapPaneWithTargetArgCommandKey")), - directionString) - }; + case FocusDirection::Left: + directionString = RS_(L"DirectionLeft"); + break; + case FocusDirection::Right: + directionString = RS_(L"DirectionRight"); + break; + case FocusDirection::Up: + directionString = RS_(L"DirectionUp"); + break; + case FocusDirection::Down: + directionString = RS_(L"DirectionDown"); + break; + case FocusDirection::Previous: + return RS_(L"SwapPaneLastUsedPane"); + case FocusDirection::NextInOrder: + return RS_(L"SwapPaneNextPaneInOrder"); + case FocusDirection::PreviousInOrder: + return RS_(L"SwapPanePreviousPaneInOrder"); + case FocusDirection::First: + return RS_(L"SwapPaneFirstPane"); } return winrt::hstring{ diff --git a/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw index 4190b0a26cb..f856d089772 100644 --- a/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw @@ -255,9 +255,17 @@ Move focus {0} {0} will be replaced with one of the four directions "DirectionLeft", "DirectionRight", "DirectionUp", "DirectionDown" - - Move focus to the {0} - {0} will be replaced with one of "LastUsedPane", "NextPaneInOrder", "PreviousPaneInOrder", "FirstPane" + + 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 @@ -266,9 +274,17 @@ Swap pane {0} {0} will be replaced with one of the four directions "DirectionLeft", "DirectionRight", "DirectionUp", "DirectionDown" - - Swap panes with the {0} - {0} will be replaced with one of "LastUsedPane", "NextPaneInOrder", "PreviousPaneInOrder", "FirstPane" + + 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 From 1c446ea61b1a0163b232c2ee5a1916cac3625588 Mon Sep 17 00:00:00 2001 From: Schuyler Rosefield Date: Thu, 26 Aug 2021 13:33:40 -0400 Subject: [PATCH 4/4] revert to try to preserve already translated resource names, remove dead resources. --- .../TerminalSettingsModel/ActionArgs.cpp | 12 +++++----- .../Resources/en-US/Resources.resw | 24 +++++-------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp index 37625d1c2df..fab78a2f1e9 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.cpp @@ -291,11 +291,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation directionString = RS_(L"DirectionDown"); break; case FocusDirection::Previous: - return RS_(L"MoveFocusLastUsedPane"); + return RS_(L"MoveFocusToLastUsedPane"); case FocusDirection::NextInOrder: - return RS_(L"MoveFocusNextPaneInOrder"); + return RS_(L"MoveFocusNextInOrder"); case FocusDirection::PreviousInOrder: - return RS_(L"MoveFocusPreviousPaneInOrder"); + return RS_(L"MoveFocusPreviousInOrder"); case FocusDirection::First: return RS_(L"MoveFocusFirstPane"); } @@ -324,11 +324,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation directionString = RS_(L"DirectionDown"); break; case FocusDirection::Previous: - return RS_(L"SwapPaneLastUsedPane"); + return RS_(L"SwapPaneToLastUsedPane"); case FocusDirection::NextInOrder: - return RS_(L"SwapPaneNextPaneInOrder"); + return RS_(L"SwapPaneNextInOrder"); case FocusDirection::PreviousInOrder: - return RS_(L"SwapPanePreviousPaneInOrder"); + return RS_(L"SwapPanePreviousInOrder"); case FocusDirection::First: return RS_(L"SwapPaneFirstPane"); } diff --git a/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw index f856d089772..9ab4507535d 100644 --- a/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw @@ -207,18 +207,6 @@ up - - first pane - - - next pane in order - - - previous pane in order - - - last used pane - previous @@ -255,13 +243,13 @@ Move focus {0} {0} will be replaced with one of the four directions "DirectionLeft", "DirectionRight", "DirectionUp", "DirectionDown" - + Move focus to the last used pane - + Move focus to the next pane in order - + Move focus to the previous pane in order @@ -274,13 +262,13 @@ Swap pane {0} {0} will be replaced with one of the four directions "DirectionLeft", "DirectionRight", "DirectionUp", "DirectionDown" - + Swap panes with the last used pane - + Swap panes with the next pane in order - + Swap panes with the previous pane in order