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

Support remapping keybindings #748

Merged
merged 12 commits into from
May 21, 2019
Merged

Support remapping keybindings #748

merged 12 commits into from
May 21, 2019

Conversation

zadjii-msft
Copy link
Member

Fixes #537.

Adds support for remappable keybindings in the profiles.json file. The keybindings look like the following:

    "keybindings": [
        {
            "keys": ["ctrl+t"],
            "command": "newTab"
        },
        {
            "keys": ["ctrl+shift+1"],
            "command": "newTabProfile0"
        },
        { "keys": ["ctrl+w"], "command": "closeTab" },
        { "keys": ["ctrl+tab"], "command": "nextTab" },
        { "keys": ["ctrl+shift+tab"], "command": "prevTab" },
        { "keys": ["ctrl+shift+pgup"], "command": "scrollUp" },
    ]

@zadjii-msft zadjii-msft added Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Area-Settings Issues related to settings and customizability, for console or terminal labels May 13, 2019
@zadjii-msft zadjii-msft added this to the Windows Terminal v1.0 milestone May 13, 2019
src/cascadia/TerminalApp/AppKeyBindings.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindings.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindings.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindings.idl Show resolved Hide resolved
src/cascadia/TerminalSettings/KeyChord.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindings.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettings/KeyChord.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettings/KeyChord.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettings/KeyChord.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettings/KeyChord.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettings/KeyChord.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettings/KeyChord.cpp Outdated Show resolved Hide resolved
@DHowett-MSFT
Copy link
Contributor

is now a good time to split the "key bindings" model from the key bindings magic? I'm concerned that the KeyBindings/AppKeyBindings object has a little too much power.

Right now, it's responsible for:

  1. loading key bindings
  2. saving them
  3. creating the defaults
  4. processing key input on request
  5. dispatching the event associated with a key binding

Should those last two live somewhere else?

@mdtauk
Copy link

mdtauk commented May 14, 2019

Everytime a new keybinding is added to the app, an entry for a customised keybinding should be added to the docs and to the profile.json file (commented out until the user wishes to change it from the default)

This way all keybindings are discoverable.

@zadjii-msft
Copy link
Member Author

@DHowett-MSFT I'm not sure if I totally get what you're saying - seems to me like you're proposing a separate KeyBindingsSerialization class?

I'm not really strongly opposed to that, but I'm not really sure what extra benefit we'd get from that. To me it seems like the serialization of the bindings is pretty tightly coupled to the actual implementation of having a map of keychord->action pairs.

Also, iirc bullet point 3 is actually handled by CascadiaSettings::_CreateDefaultKeybindings

{
modifiers |= KeyModifiers::Alt;
}
else if (part == SHIFT_KEY)
Copy link
Member

Choose a reason for hiding this comment

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

Do we have to worry about left-shift vs right-shift? Do we want to?

Copy link
Contributor

Choose a reason for hiding this comment

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

We recently learned that right alt is altgr sometimes?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is true, but I'm not sure UWP can differentiate between the two in the KeyEvent. I'm pretty sure there's only a Ctrl, Shift, and Alt, and not a left/right version :/

If we find out otherwise, then the entire KeyModifiers structure might need to be updated, as well as any consumers.

// If we weren't able to find a match, throw an exception.
if (!foundKey)
{
throw hresult_invalid_argument();
Copy link
Member

Choose a reason for hiding this comment

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

Do we also want an error dialogue box like in #622? Or maybe just ignore it? I'm ok with this behavior for now but we should probably decide on behavior and file it as a separate issue for after.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea probably, but I'll make that a separate task for once both this and 622 are merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here's a concern: should not being able to deserialize a single key binding blast the entire profiles into outer space? even with an error message, that sucks

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, I don't think it should. I'd think that failing to parse a single key would still ignore the bad binding, but display the error (somehow)

…dings

# Conflicts:
#	src/cascadia/TerminalApp/AppKeyBindings.cpp
  * Update the appkeybindings vector to a map
  * Update the strings to wchar_t*'s to avoid ctoring a ton on startup
src/cascadia/TerminalApp/AppKeyBindings.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindings.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindings.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindings.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindings.idl Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindings.idl Show resolved Hide resolved
src/cascadia/TerminalSettings/KeyChord.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettings/KeyChord.cpp Outdated Show resolved Hide resolved
// If we weren't able to find a match, throw an exception.
if (!foundKey)
{
throw hresult_invalid_argument();
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's a concern: should not being able to deserialize a single key binding blast the entire profiles into outer space? even with an error message, that sucks

@DHowett-MSFT
Copy link
Contributor

More to the point about idl, my concern is that key binding serialization lives in a totally different component than settings serialization now.. hmm. Is this something we can reconcile?

@zadjii-msft
Copy link
Member Author

@DHowett-MSFT great point on that. The TerminalApp is the only thing doing any serializing, it should probably be the one responsible for doing this serializing. I could add a helper class for serializing just the keychord, like KeyChordSerializer, with just a couple statics on it.

The AppKeyBindings is actually an App component, so it makes sense to couple it's serialization directly to it's class, just like profiles, globals and schemes.

Copy link
Contributor

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

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

This seems mostly reasonable to me.

src/cascadia/TerminalApp/AppKeyBindings.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindings.cpp Show resolved Hide resolved
Copy link
Contributor

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

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

Though, we changed + to plus, but - . , are still symbolic. someone in the future might bind ctrl+- and ctrl+plus as zoom out and zoom in respectively, and that seems unsymmetric

@timheuer
Copy link
Member

Was looking at this in conjunction with resolving suggestions for #805. The XAML framework uses Windows::System::VirtualKey and Windows::System::VirtualKeyModifiers...is there a reason that Terminal should create their own types here that are now maintaining modifiers and enum values for something that already exists? Retrieving the keybindings with a KeyChord that has it's own values is proving to be challenging using them anywhere in the UI due to different types and not being able to cast them accordingly well.

@zadjii-msft
Copy link
Member Author

@timheuer that's a really good idea. I've pulled it out to #877, because yea, there's really no need to use our own types.

@zadjii-msft
Copy link
Member Author

@DHowett-MSFT is CLA bot acting up? Can we manually trigger it somehow? Looks like it's broken on #710 too

@zadjii-msft zadjii-msft merged commit 29e3808 into master May 21, 2019
@zadjii-msft zadjii-msft deleted the dev/migrie/f/keybindings branch May 21, 2019 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support remapping keybindings
10 participants