Skip to content

Commit 22887d7

Browse files
authored
Preview tab switching with the ATS (#7796)
## Summary of the Pull Request ![preview-ats-000](https://user-images.githubusercontent.com/18356694/94801728-18302a00-03ac-11eb-851d-760b92ebb46f.gif) This PR enables the ATS to display the active tab as the user navigates the tab switcher. We do this by dispatching the tab switch actions as the user navigates the menu, and manually _not_ focusing the new tab when the tab switcher is open. ## References * #6732 - original tab switcher PR * #6689 - That's a more involved, generic version of this, but this PR will be enough to stop most of the complaints hopefully ## PR Checklist * [x] Closes #7409 * [x] I work here * [ ] Tests added/passed * [n/a] Requires documentation to be updated ## Validation Steps Performed Opened tabs, tabbed through the menu, verified that it did what I'd expect
1 parent 2608e94 commit 22887d7

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/cascadia/TerminalApp/CommandPalette.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ namespace winrt::TerminalApp::implementation
9393
}
9494
_sizeChangedRevoker.revoke();
9595
});
96+
97+
_filteredActionsView().SelectionChanged({ this, &CommandPalette::_selectedCommandChanged });
9698
}
9799

98100
// Method Description:
@@ -115,6 +117,29 @@ namespace winrt::TerminalApp::implementation
115117
_filteredActionsView().ScrollIntoView(_filteredActionsView().SelectedItem());
116118
}
117119

120+
// Method Description:
121+
// - Called when the command selection changes. We'll use this in the tab
122+
// switcher to "preview" tabs as the user navigates the list of tabs. To
123+
// do that, we'll dispatch the switch to tab command for this tab, but not
124+
// dismiss the switcher.
125+
// Arguments:
126+
// - <unused>
127+
// Return Value:
128+
// - <none>
129+
void CommandPalette::_selectedCommandChanged(const IInspectable& /*sender*/,
130+
const Windows::UI::Xaml::RoutedEventArgs& /*args*/)
131+
{
132+
if (_currentMode == CommandPaletteMode::TabSwitchMode)
133+
{
134+
const auto& selectedCommand = _filteredActionsView().SelectedItem();
135+
if (const auto& command = selectedCommand.try_as<TerminalApp::Command>())
136+
{
137+
const auto& actionAndArgs = command.Action();
138+
_dispatch.DoAction(actionAndArgs);
139+
}
140+
}
141+
}
142+
118143
void CommandPalette::_previewKeyDownHandler(IInspectable const& /*sender*/,
119144
Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e)
120145
{

src/cascadia/TerminalApp/CommandPalette.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ namespace winrt::TerminalApp::implementation
6464
void _keyUpHandler(Windows::Foundation::IInspectable const& sender,
6565
Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e);
6666

67+
void _selectedCommandChanged(Windows::Foundation::IInspectable const& sender,
68+
Windows::UI::Xaml::RoutedEventArgs const& args);
69+
6770
void _updateUIForStackChange();
6871

6972
void _rootPointerPressed(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e);

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,20 @@ namespace winrt::TerminalApp::implementation
20282028
_tabContent.Children().Clear();
20292029
_tabContent.Children().Append(tab->GetRootElement());
20302030

2031-
tab->SetFocused(true);
2031+
// GH#7409: If the tab switcher is open, then we _don't_ want to
2032+
// automatically focus the new tab here. The tab switcher wants
2033+
// to be able to "preview" the selected tab as the user tabs
2034+
// through the menu, but if we toss the focus to the control
2035+
// here, then the user won't be able to navigate the ATS any
2036+
// longer.
2037+
//
2038+
// When the tab swither is eventually dismissed, the focus will
2039+
// get tossed back to the focused terminal control, so we don't
2040+
// need to worry about focus getting lost.
2041+
if (CommandPalette().Visibility() != Visibility::Visible)
2042+
{
2043+
tab->SetFocused(true);
2044+
}
20322045

20332046
// Raise an event that our title changed
20342047
_titleChangeHandlers(*this, tab->GetActiveTitle());

0 commit comments

Comments
 (0)