-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
List View: Support insert before/after keyboard shortcuts when focus is within the list view #60651
List View: Support insert before/after keyboard shortcuts when focus is within the list view #60651
Conversation
…is within the list view
Size Change: +63 B (0%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Thank you, @andrewserong! The shortcuts are working really well ✅
I tested changes with multiple blocks, including ones that support this feature based on the directInsertBlock
setting.
@@ -189,6 +194,30 @@ function ListViewBlockSelectButton( | |||
updateFocusAndSelection( updatedBlocks[ 0 ], false ); | |||
} | |||
} | |||
} else if ( isMatch( 'core/block-editor/insert-before', event ) ) { |
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.
Do we share logic here with the normal canvas? Is it worth unifying?
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.
The logic for the list view needs to be slightly different to the editor canvas, as the list view does a couple of things differently:
- We determine the blocks to update based on the focused item in addition to the block selection (so if the focused list view item is outside of the selection, we ignore the selection and use the focused list view item as the "anchor" block to add blocks either before or after)
- After insertion, we switch focus back to the list view item so that focus remains within the list view
So, I'm not too sure how feasible it'd be to unify this further with how the editor canvas handles things. That said, it could be worth exploring, and to look into how to either neaten things or consolidate things further in a separate PR as this onKeyDownHandler
callback is quite long, so if nothing else it might work to move the callback into a hook? In any case, I'll merge this PR in its current form for now, and we can look into code quality follow-ups separately 🙂
Thanks for the review! 🙇 |
What?
Part of #60099
Enable keyboard shortcuts for inserting before or after list view items when focus is within the list view. (The keyboard shortcuts are currently Option+CMD+T to insert before and Option+CMD+Y to insert after).
Why?
These keyboard shortcuts work when focus is within the editor canvas, and it's already supported in the list view via the block settings menu. If you're used to these keyboard shortcuts and have focus within the list view, it feels a little broken if the keyboard shortcuts don't work there. This brings consistency to these keyboard shortcuts.
How?
Testing Instructions
Option+CMD+T
)Option+CMD+Y
)Screenshots or screencast
2024-04-11.15.47.36.mp4