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

Refactor ActionMap and Command to use ActionIDs #17162

Open
wants to merge 80 commits into
base: main
Choose a base branch
from

Conversation

PankajBhojwani
Copy link
Contributor

@PankajBhojwani PankajBhojwani commented Apr 30, 2024

Summary of the Pull Request

As outlined in #16816, refactor ActionMap to use the new action IDs added in #16904

Detailed description of the pull request

See the spec!
 

Validation steps performed

  • Legacy style commands are parsed correctly (and rewritten to the new format)
  • Actions are still layered correctly and their IDs can be used to 'overwrite' actions in earlier layers
  • Keybindings that refer to an ID defined in another layer work correctly
  • User-defined actions without an ID have one generated for them (and their settings file is edited with it)
  • Schema updated

References and Relevant Issues

#16816

PR Checklist

{
if (cmd.ActionAndArgs().Action() != ShortcutAction::Invalid)
// Only populate AvailableActions with actions that haven't been visited already.
const auto actionID = Hash(cmd.ActionAndArgs());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately we still have to use InternalActionID to populate the available action dropdown in the SUI since we don't have a Terminal.<> id for every configuration of each shortcut action and its args

This comment has been minimized.

Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

Mostly nits, and 1 bug.
I'm not sure I understood how all the changes fit together in the grand scheme of things. I'm not so deep into the ActionMap code. 🙈

src/cascadia/TerminalSettingsModel/ActionMap.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsModel/ActionMap.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsModel/ActionMap.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsModel/ActionMap.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsModel/ActionMap.cpp Outdated Show resolved Hide resolved
@PankajBhojwani
Copy link
Contributor Author

I'm not sure I understood how all the changes fit together in the grand scheme of things

THIS

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.

this one is much scarier

@@ -1023,7 +1023,8 @@ namespace winrt::TerminalApp::implementation
// NewTab(ProfileIndex=N) action
NewTerminalArgs newTerminalArgs{ profileIndex };
NewTabArgs newTabArgs{ newTerminalArgs };
auto profileKeyChord{ _settings.ActionMap().GetKeyBindingForAction(ShortcutAction::NewTab, newTabArgs) };
const auto id = fmt::format(FMT_COMPILE(L"Terminal.OpenNewTabProfile{}"), profileIndex);
const auto profileKeyChord{ _settings.ActionMap().GetKeyBindingForAction(id) };
Copy link
Member

Choose a reason for hiding this comment

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

There 100% is a issue right now for "I rebound keys for new tab profile N, but the dropdown still has the old ones" and I'm guessing this will solve that (because people can rebind the key for the literal Terminal.OpenNewTabProfile5 rather than just making a new Command for it)

Copy link
Member

Choose a reason for hiding this comment

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

#13943 I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep this fixes that! Also fixes it in the cmd palette

{ "command": "paste", "keys": "ctrl+v" },
{ "command": "find", "keys": "ctrl+shift+f" },
{ "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
{ "id": "Terminal.CopySelectedText", "keys": "ctrl+c" },
Copy link
Member

Choose a reason for hiding this comment

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

Okay so, if I want to

  • Remove the ctrl+shift+c keybinding set in the defaults
  • AND add a keybinding to alt+c

how do I do that now?

Does this add a ctrl+c keybinding to Terminal.CopySelectedText, or replace the original ctrl+shift+c?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this add a ctrl+c keybinding to Terminal.CopySelectedText, or replace the original ctrl+shift+c?

It only adds!

Remove the ctrl+shift+c keybinding set in the defaults

Then you add {"id": null, "keys": "ctrl+shift+c"} into the keybindings array

AND add a keybinding to alt+c

Add {"id": "<id of the command>", "keys": "alt+c"} into keybindings

{ "command": "copy", "keys": ["ctrl+c"] },
{ "command": { "action": "copy", "singleLine": false }, "keys": ["ctrl+shift+c"] },
{ "command": { "action": "copy", "singleLine": true }, "keys": ["alt+shift+c"] },
{ "command": "copy", "id": "Test.CopyNoArgs", "keys": ["ctrl+c"] },
Copy link
Member

Choose a reason for hiding this comment

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

for my own notes: the commands in this test needed id's because the JSON was getting parsed as origin::none? if it was origin::user, they wouldn't need id's, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, since they are Origin::None we will not generate ids for them and so the ActionMap will refuse to add them.

Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

1 nit left. I think it's worth addressing, but otherwise LGTM from my side.

src/cascadia/TerminalSettingsModel/ActionMap.cpp Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pre-seeded actions from userDefaults.json should be removed after adding IDs
4 participants