-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Allow setting the action on Actions page #10220
Conversation
afcc655
to
1453376
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than trying out the ComboBox.Text
property instead of SelectedItem
,
|
||
// Check for this special case: | ||
// we're changing the key chord, | ||
// but the new key chord is already in use | ||
if (args.OldKeys().Modifiers() != args.NewKeys().Modifiers() || args.OldKeys().Vkey() != args.NewKeys().Vkey()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: do we also want to display a warning for something like "this action already has a keybinding, are you sure you want to add another?"
I know having multiple keybindings for an action is totally fine and not really 'conflicting', but with the long list of actions we currently show it might be easy for a user to miss that they've already set a keybinding for an action but forgot about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally okay with having this be a follow-up or a "wait until someone asks for it before we implement it" kinda thing, just wanted to know if it's been discussed already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting!
// ProposedAction: the entry selected by the combo box; may disagree with the settings model. | ||
// CurrentAction: the combo box item that maps to the settings model value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this description... Why can it disagree with the settings model? And why does the combo box item map to a settings model value? The way I understand the code, CurrentAction
is the actual action identifier/name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really it's because we have the "cancel"/"ok" system (aka the "edit mode" system). CurrentAction
serves as...
- a record of what to set
ProposedAction
to on a cancellation - a form of translation between
ProposedAction
and the settings model
If we got rid of the "edit mode" system, we don't have to worry about (1) anymore. To get rid of (2), KeyBindingViewModel
would need a reference to the ActionMap
. But even then, I think it's better to keep the ActionMap
reference at a higher layer so that we can identify conflicting key bindings and key chords before editing the settings model. I think that's a better separation of responsibilities imo.
|
||
// If the action was changed, | ||
// update the settings model and view model appropriately | ||
auto attemptSetAction = [=]() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attemptSetAction
is always called when attemptRebindKeys
is.
You can just merge the two lambdas into one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup! I really only separated them out so that it's easier to read. I'm down to combine them, but I'm still worried about readability. Would something like this be clear maybe?
auto applyChangesToSettingsModel = [](){
// code for 'attemptRebindKeys'
// code for 'attemptSetAction'
};
Dude, I have no idea where the Edit: @leonMSFT |
Since we're so close to this merging, I'm gonna add "add action" in a separate PR, not this one. I'll leave that for tomorrow though. I hope it'll only take like half a day to implement tbh. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think the combined
applyChangesToSettingsModel
would be a good idea as it prevents you from forgetting to call both at once - You wrote an excellent description for ProposedAction/CurrentAction: This should IMO be part of the comment in the code
## Summary of the Pull Request This adds the "add new" button to the actions page. It build on the work of #10220 by basically just adding a new list item to the top of the key binding list. This also makes it so that if you click the "accept changes" button when you have an invalid key chord, we don't do anything. ## References #6900 - Actions page Epic #9427 - Actions page design doc #10220 - Actions page PR - set action ## Detailed Description of the Pull Request / Additional comments - `ModifyKeyBindingEventArgs` is used to introduce new key bindings. We just ignore `OldKeys` and `OldActionName` because both didn't exist before. - `IsNewlyAdded` tracks if this is an action that was added, but has not been confirmed to add to the settings model. - `CancelChanges()` is directly bound to the cancel button. This allows us to delete the key binding when it's clicked on a "newly added" action. ## Validation Steps Performed - Cancel: - Deletes the action (because it doesn't truly exist until you confirm changes) - Accept: - Adds the new action. - If you attempt to edit it, the delete button is back. - Add Action: - Delete button should not be visible (redundant with 'Cancel') - Action should be initialized to a value - Key chord should be empty - Cannot add another action if a newly added action exists - Keyboard interaction: - escape --> cancel - enter --> accept - Accessibility: - "add new" button has a name - Interaction with other key bindings: - editing another action --> delete the "newly added" action (it hasn't been added yet) - only one action can be edited at a time
🎉 Handy links: |
🎉 Handy links: |
Summary of the Pull Request
This introduces the ability to set the action for a key binding. A combo box is used to let the user select a new action.
References
#6900 - Actions page Epic
#9427 - Actions page design doc
#9949 - Actions page PR
Detailed Description of the Pull Request / Additional comments
Settings Model Changes
ActionAndArgs
ShortcutAction
ActionMap
AvailableActions
provides a map of all the "acceptable" actions to choose from. This is a merged list of (1) all{ "command": X }
style actions and (2) any actions with args that are already defined in the ActionMap (or any parents).RegisterKeyBinding
introduces a new unnamed key binding to the action map.Editor Changes
RebindKeysEventArgs
-->ModifyKeyBindingEventArgs
AvailableActionAndArgs
KeyBindingViewModel
needs this so that we can populate the combo boxActions
stores and maintains this though. We populate this from the settings model on navigation.ProposedAction
vsCurrentAction
ProposedKeys
andKeys
, we need a way to distinguish the value from the settings model and the value of the control (i.e. combo box).CurrentAction
--> settings modelProposedAction
--> combo box selected itemValidation Steps Performed
{ "command": "closePane" }
. This is intentional because we want to prevent all modifications to the command palette.