Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable shortcut while CommandPalette is open #8586

Merged
4 commits merged into from Dec 18, 2020
Merged

Enable shortcut while CommandPalette is open #8586

4 commits merged into from Dec 18, 2020

Conversation

ghost
Copy link

@ghost ghost commented Dec 14, 2020

This commit introduces direct shortcut dispatch to TerminalPage, which
allows it to respond to key bindings before the command palette.

This allows the user to use shortcuts from the command palette while
it's open.

Closes #6679

@ghost ghost added Area-CmdPal Command Palette issues and features Area-User Interface Issues pertaining to the user interface of the Console or Terminal Issue-Task It's a feature request, but it doesn't really need a major design. Priority-2 A description (P2) Product-Terminal The new Windows Terminal. labels Dec 14, 2020
@DHowett
Copy link
Member

DHowett commented Dec 14, 2020

You may need @Don-Vito's help since he removed _dispatch from the command palette!

@Don-Vito
Copy link
Contributor

@Hegunumo - please let me know if I can be useful 😊

@zadjii-msft zadjii-msft assigned ghost Dec 15, 2020
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<requesting changes as a mental note that this needs to be merged with main>

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 15, 2020
@ghost
Copy link
Author

ghost commented Dec 16, 2020

@Don-Vito I'm trying to include AppLogic.h into CommandPalette.cpp, but I keep getting error. I know this might be a trivial thing.

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 16, 2020
@Don-Vito
Copy link
Contributor

Don-Vito commented Dec 16, 2020

@Don-Vito I'm trying to include AppLogic.h into CommandPalette.cpp, but I keep getting error. I know this might be a trivial thing.

@Hegunumo -
* Currently the dispatching logic has moved to TerminalPage - please see TerminalPage::_OnDispatchCommandRequested and TerminalPage::_OnCommandLineExecutionRequested for example.
* The idea behind this is that CommandPalette is becoming a control stripped of business logic
* One of the benefits if this approach is that TerminalPage already has _settings and you don't need to load it.
* I believe that what we can do is to register another event to CommandPalette in TerminalPage::Create

UPDATE: please see comment below for what I believe is much better approach

@Don-Vito
Copy link
Contributor

Don-Vito commented Dec 16, 2020

@Hegunumo - I reviewed the solution and did a small PoC. Since key down sends RoutedEvent we can handle it at the relevant element in the hierarchy. Which means we can apply the following logic:

  • As today, CommandPalette intercepts the key down events to see if the key was intended to it (e.g., navigation within palette)
  • CommandPalette does not handle events that are not intended to it
  • TerminalPage catches the event and handles if it has a relevant KeyBinding.

This approach will also solve the problems like:

  • KeyBindings are not working when search control is open.
  • KeyBindings are not working when menu is open.

So my suggested approach is:

  1. Register KeyDownHandler in TerminalPage that does the logic that you have written
  2. Remove the _bindings completely from the Palette
  3. Enjoy viewing how the bindings work from every place in UI

And the handling in the TerminalPage::_KeyDownHandler will be quite straightforward. Something like:

const auto actionAndArgs = _settings.KeyMap().TryLookup(kc);
if (actionAndArgs)
{
   if (CommandPalette().Visibility() == Visibility::Visible && actionAndArgs.Action() != ShortcutAction::ToggleCommandPalette)
   {
            CommandPalette().Visibility(Visibility::Collapsed);
   }
   _actionDispatch->DoAction(actionAndArgs);
   e.Handled(true);
}

@zadjii-msft - FYI. This will extend this contribution into "Make key bindings universally available" 💪

@ghost
Copy link
Author

ghost commented Dec 17, 2020

@Don-Vito It wored! Please review.

Copy link
Contributor

@Don-Vito Don-Vito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the small nit, looks great. But might be a bit confusing, since in the tabswitcher mode the binding is still handled by Palette.

If possible, I would suggest to remove the _bindings entirely from CommandPaltte (I mean delete _bindings attribute from palette and its usages in CommandPaltte::SetKeyBindings and CommandPaltte::_keyDownHandler)

// - e: the KeyRoutedEventArgs containing info about the keystroke.
// Return Value:
// - <none>
void TerminalPage::_CommandPaletteKeyDownHandler(Windows::Foundation::IInspectable const& /*sender*/, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming this into _KeyDownHandler because it now serves the TerminalPage in general: it runs the bindings no matter where you are. It does have a specific logic for CommandPalette, but tomorrow we will probably want to do more stuff.

@zadjii-msft
Copy link
Member

Just playing with this, it feels really good. I'm a little shocked that this doesn't work for the new tab dropdown. Maybe that's not technically a child of the TerminalPage - I think flyouts might technically have some other crazy XAML root that lets them escape the window confines.

I'll double check the code now, but from a UX perspective this seems good to me

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay yea I only have the same nit as Don-Vito. Thanks for doing this!

@zadjii-msft zadjii-msft added the Needs-Second It's a PR that needs another sign-off label Dec 17, 2020
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned. Does this break preview mode? The tab switcher UI that Ctrl-Tab activates relies on commands to be dispatched without the palette being hidden. Will this force the command palette to be hidden when it should not be?

Otherwise, this is exactly what I wanted. I have always wanted us to move the key binding handler into TerminalPage!!

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 18, 2020
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 18, 2020
@Don-Vito
Copy link
Contributor

Don-Vito commented Dec 18, 2020

@Hegunumo - wait 😊. The palette should collapse (it is ephemeral, if we don't collapse it might show invalid data). What @DHowett means is to make sure that the Palette is not collapsed in the tab switcher mode (especially when custom keybindings are used).

@Don-Vito
Copy link
Contributor

To @DHowett's initial concern - Control+Tab is handled explicitly in CommandPalette::_previewKeyDownHandler - so it will work.

And for my concern it appears that custom bindings are not triggering TabSwitcher.

So @Hegunumo's original solution works (before he removed the collapsing of the palette).

I still strongly recommend removing the _bindings from Palette - but we can do it in a follow-up PR.

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for testing it and for explaining it. @Hegunumo, good work!

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Dec 18, 2020
@ghost
Copy link

ghost commented Dec 18, 2020

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 01a0490 into microsoft:main Dec 18, 2020
MycroftKang added a commit to MycroftKang/terminal that referenced this pull request Dec 27, 2020
ghost pushed a commit that referenced this pull request Jan 7, 2021
Following up #8586 by @Hegunumo,
fully remove the command dispatching logic from Command Palette.

Currently Command Palette might dispatch command in Tab Switcher mode.
This leads to several inconsistencies:
* Only the commands with the same key modifier as an ATS anchor will be issued
* This command will not close the TabSwitcher 
(while commands issued from TerminalPage do).

Implementation details:
* Pass KeyMapping rather than binding to CommandPalette
* Use this mapping inside previewKeyDownHandler of ATS to detect
if previous tab or next tab bindings were engaged. 
No need to handle Ctrl+Tab explicitly anymore - 
it is handled as any other binding.
* Cleanup the logic in TerminalPage::_SelectNextTab 
that checks if CommandPalette is visible.
It is not required anymore, as visible palette would intercept the call.
* Remove dependency of TerminalPage on AppLogic
that was introduced lately .
mpela81 pushed a commit to mpela81/terminal that referenced this pull request Jan 28, 2021
This commit introduces direct shortcut dispatch to TerminalPage, which
allows it to respond to key bindings before the command palette.

This allows the user to use shortcuts from the command palette while
it's open.

Closes microsoft#6679
mpela81 pushed a commit to mpela81/terminal that referenced this pull request Jan 28, 2021
…8628)

Following up microsoft#8586 by @Hegunumo,
fully remove the command dispatching logic from Command Palette.

Currently Command Palette might dispatch command in Tab Switcher mode.
This leads to several inconsistencies:
* Only the commands with the same key modifier as an ATS anchor will be issued
* This command will not close the TabSwitcher 
(while commands issued from TerminalPage do).

Implementation details:
* Pass KeyMapping rather than binding to CommandPalette
* Use this mapping inside previewKeyDownHandler of ATS to detect
if previous tab or next tab bindings were engaged. 
No need to handle Ctrl+Tab explicitly anymore - 
it is handled as any other binding.
* Cleanup the logic in TerminalPage::_SelectNextTab 
that checks if CommandPalette is visible.
It is not required anymore, as visible palette would intercept the call.
* Remove dependency of TerminalPage on AppLogic
that was introduced lately .
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CmdPal Command Palette issues and features Area-User Interface Issues pertaining to the user interface of the Console or Terminal AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Needs-Second It's a PR that needs another sign-off Priority-2 A description (P2) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

commandPalette keybinding should close the palette when it's open
4 participants