-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix save, undo and redo keyboard shortcuts in navigation editor #28257
Conversation
…ved to upper layer so both - save button and cmd+s shortcut are using the same piece of code.
Size Change: +2.45 kB (0%) Total Size: 1.28 MB
ℹ️ View Unchanged
|
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.
Something I didn't realise is that there is already some code for the shortcut:
gutenberg/packages/edit-navigation/src/components/layout/shortcuts.js
Lines 13 to 22 in b864c5d
useShortcut( 'core/edit-navigation/save-menu', useCallback( ( event ) => { event.preventDefault(); saveBlocks(); } ), { bindGlobal: true, } ); gutenberg/packages/edit-navigation/src/components/layout/shortcuts.js
Lines 49 to 57 in b864c5d
registerShortcut( { name: 'core/edit-navigation/save-menu', category: 'global', description: __( 'Save the navigation currently being edited.' ), keyCombination: { modifier: 'primary', character: 's', }, } );
Sorry for that, I just thought they hadn't been implemented. The existing implementation uses the useShortcut
and registerShortcut
functions, the idea behind that APIs is that someday shortcut customisation can be added as a feature.
None of these shortcuts seem to be working though, so it'd be good to figure out why and fix them.
It is not working as |
@grzim I'm ok with only using hooks. I'm not completely sure why it's a component, but I think other editors also implement it this way using shortcuts, and that was likely copied in the navigation editor. |
@talldan I have made a little investigation and it is just like you said. Editors implement it this way in order to make it possible to add shortcuts to blocks like this:
The key concept is to make it possible to nest |
…s. Use this mechanism
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.
So here we can either use hooks as this would be a cleaner solution or leave it as it is now what makes it less clean but consistent with other editors. In my opinion - consistency wins here.
Agreed. Could always explore refactoring it all to hooks in a separate PR.
I recall another potential issue with the Register
components is that they always have to come before the actual shortcut component, so definite scope for improvement.
Anyway, This is working nicely, I rebased locally to bring in some other recent fixes and can confirm save, undo, and redo are now working well. Thanks @grzim 🎉
Saving post logic moved to upper layer so both - save button and cmd+s shortcut are using the same piece of code.
Description
Regarding #28213 keyboard shortcut to save navigation added.
The listener is added to the editor. As the editor does not play any interactive role, I have disabled the linter rule
eslint-disable-next-line jsx-a11y/no-static-element-interactions
How has this been tested?
Tested manually
Types of changes
New feature
Checklist: