Make index in closeOtherTabs and closeTabsAfter optional (#7390)
## Summary of the Pull Request The `index` action argument is now optional for `closeOtherTabs` and `closeTabsAfter`. When `index` is not defined, `index` is set to the focused tab's index. Also, adds the non-index version of these actions to defaults.json. ## PR Checklist * [X] Closes #7181 * [X] CLA signed * [X] Tests passed * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [X] Schema updated. ## Validation Steps Performed Opened 4 tabs and ran closeOtherTabs/closeTabsAfter from command palette.
This commit is contained in:
parent
64f10a0c9d
commit
2fdc88f7ea
|
@ -397,14 +397,16 @@
|
|||
"properties": {
|
||||
"action": { "type": "string", "pattern": "closeOtherTabs" },
|
||||
"index": {
|
||||
"type": "integer",
|
||||
"oneOf": [
|
||||
{ "type": "integer" },
|
||||
{ "type": null }
|
||||
],
|
||||
"default": "",
|
||||
"description": "Close the tabs other than the one at this index."
|
||||
"description": "Close the tabs other than the one at this index. If no index is provided, use the focused tab's index."
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"required": [ "index" ]
|
||||
]
|
||||
},
|
||||
"CloseTabsAfterAction": {
|
||||
"description": "Arguments for a closeTabsAfter action",
|
||||
|
@ -414,14 +416,16 @@
|
|||
"properties": {
|
||||
"action": { "type": "string", "pattern": "closeTabsAfter" },
|
||||
"index": {
|
||||
"type": "integer",
|
||||
"oneOf": [
|
||||
{ "type": "integer" },
|
||||
{ "type": null }
|
||||
],
|
||||
"default": "",
|
||||
"description": "Close the tabs following the tab at this index."
|
||||
"description": "Close the tabs following the tab at this index. If no index is provided, use the focused tab's index."
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"required": [ "index" ]
|
||||
]
|
||||
},
|
||||
"Keybinding": {
|
||||
"additionalProperties": false,
|
||||
|
|
|
@ -339,19 +339,27 @@ namespace winrt::TerminalApp::implementation
|
|||
|
||||
winrt::hstring CloseOtherTabsArgs::GenerateName() const
|
||||
{
|
||||
// "Close tabs other than index {0}"
|
||||
return winrt::hstring{
|
||||
fmt::format(std::wstring_view(RS_(L"CloseOtherTabsCommandKey")),
|
||||
_Index)
|
||||
};
|
||||
if (_Index)
|
||||
{
|
||||
// "Close tabs other than index {0}"
|
||||
return winrt::hstring{
|
||||
fmt::format(std::wstring_view(RS_(L"CloseOtherTabsCommandKey")),
|
||||
_Index.Value())
|
||||
};
|
||||
}
|
||||
return RS_(L"CloseOtherTabsDefaultCommandKey");
|
||||
}
|
||||
|
||||
winrt::hstring CloseTabsAfterArgs::GenerateName() const
|
||||
{
|
||||
// "Close tabs after index {0}"
|
||||
return winrt::hstring{
|
||||
fmt::format(std::wstring_view(RS_(L"CloseTabsAfterCommandKey")),
|
||||
_Index)
|
||||
};
|
||||
if (_Index)
|
||||
{
|
||||
// "Close tabs after index {0}"
|
||||
return winrt::hstring{
|
||||
fmt::format(std::wstring_view(RS_(L"CloseTabsAfterCommandKey")),
|
||||
_Index.Value())
|
||||
};
|
||||
}
|
||||
return RS_(L"CloseTabsAfterDefaultCommandKey");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -495,7 +495,7 @@ namespace winrt::TerminalApp::implementation
|
|||
struct CloseOtherTabsArgs : public CloseOtherTabsArgsT<CloseOtherTabsArgs>
|
||||
{
|
||||
CloseOtherTabsArgs() = default;
|
||||
GETSET_PROPERTY(uint32_t, Index, 0);
|
||||
GETSET_PROPERTY(winrt::Windows::Foundation::IReference<uint32_t>, Index, nullptr);
|
||||
|
||||
static constexpr std::string_view IndexKey{ "index" };
|
||||
|
||||
|
@ -523,7 +523,7 @@ namespace winrt::TerminalApp::implementation
|
|||
struct CloseTabsAfterArgs : public CloseTabsAfterArgsT<CloseTabsAfterArgs>
|
||||
{
|
||||
CloseTabsAfterArgs() = default;
|
||||
GETSET_PROPERTY(uint32_t, Index, 0);
|
||||
GETSET_PROPERTY(winrt::Windows::Foundation::IReference<uint32_t>, Index, nullptr);
|
||||
|
||||
static constexpr std::string_view IndexKey{ "index" };
|
||||
|
||||
|
|
|
@ -134,11 +134,11 @@ namespace TerminalApp
|
|||
|
||||
[default_interface] runtimeclass CloseOtherTabsArgs : IActionArgs
|
||||
{
|
||||
UInt32 Index { get; };
|
||||
Windows.Foundation.IReference<UInt32> Index { get; };
|
||||
};
|
||||
|
||||
[default_interface] runtimeclass CloseTabsAfterArgs : IActionArgs
|
||||
{
|
||||
UInt32 Index { get; };
|
||||
Windows.Foundation.IReference<UInt32> Index { get; };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -415,7 +415,21 @@ namespace winrt::TerminalApp::implementation
|
|||
{
|
||||
if (const auto& realArgs = actionArgs.ActionArgs().try_as<TerminalApp::CloseOtherTabsArgs>())
|
||||
{
|
||||
uint32_t index = realArgs.Index();
|
||||
uint32_t index;
|
||||
if (realArgs.Index())
|
||||
{
|
||||
index = realArgs.Index().Value();
|
||||
}
|
||||
else if (auto focusedTabIndex = _GetFocusedTabIndex())
|
||||
{
|
||||
index = *focusedTabIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do nothing
|
||||
actionArgs.Handled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove tabs after the current one
|
||||
while (_tabs.Size() > index + 1)
|
||||
|
@ -438,7 +452,21 @@ namespace winrt::TerminalApp::implementation
|
|||
{
|
||||
if (const auto& realArgs = actionArgs.ActionArgs().try_as<TerminalApp::CloseTabsAfterArgs>())
|
||||
{
|
||||
uint32_t index = realArgs.Index();
|
||||
uint32_t index;
|
||||
if (realArgs.Index())
|
||||
{
|
||||
index = realArgs.Index().Value();
|
||||
}
|
||||
else if (auto focusedTabIndex = _GetFocusedTabIndex())
|
||||
{
|
||||
index = *focusedTabIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do nothing
|
||||
actionArgs.Handled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove tabs after the current one
|
||||
while (_tabs.Size() > index + 1)
|
||||
|
|
|
@ -646,4 +646,10 @@
|
|||
<data name="DarkGrayColorButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
|
||||
<value>Dark Gray</value>
|
||||
</data>
|
||||
</root>
|
||||
<data name="CloseOtherTabsDefaultCommandKey" xml:space="preserve">
|
||||
<value>Close all other tabs</value>
|
||||
</data>
|
||||
<data name="CloseTabsAfterDefaultCommandKey" xml:space="preserve">
|
||||
<value>Close all tabs after the current tab</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1304,9 +1304,9 @@ namespace winrt::TerminalApp::implementation
|
|||
|
||||
// Method Description:
|
||||
// - Returns the index in our list of tabs of the currently focused tab. If
|
||||
// no tab is currently selected, returns -1.
|
||||
// no tab is currently selected, returns nullopt.
|
||||
// Return Value:
|
||||
// - the index of the currently focused tab if there is one, else -1
|
||||
// - the index of the currently focused tab if there is one, else nullopt
|
||||
std::optional<uint32_t> TerminalPage::_GetFocusedTabIndex() const noexcept
|
||||
{
|
||||
// GH#1117: This is a workaround because _tabView.SelectedIndex()
|
||||
|
|
|
@ -291,6 +291,8 @@
|
|||
// Tab Management
|
||||
// "command": "closeTab" is unbound by default.
|
||||
// The closeTab command closes a tab without confirmation, even if it has multiple panes.
|
||||
{ "command": "closeOtherTabs" },
|
||||
{ "command": "closeTabsAfter" },
|
||||
{ "command": "newTab", "keys": "ctrl+shift+t" },
|
||||
{ "command": { "action": "newTab", "index": 0 }, "keys": "ctrl+shift+1" },
|
||||
{ "command": { "action": "newTab", "index": 1 }, "keys": "ctrl+shift+2" },
|
||||
|
|
Loading…
Reference in a new issue