-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[lexical-playground] Feature: Add more keyboard shortcuts #6754
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
add ShortcutsPlugin add ToolbarContext to share state between ShortcutsPlugin and ToolbarPlugin
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 code here looks great, very straightforward and easy to read through. I like the extensive tests and other refactoring here. I think this would provide a great example for someone who wanted to implement a full suite of keyboard shortcuts for their own editor.
packages/lexical-playground/src/plugins/ShortcutsPlugin/shortcuts.ts
Outdated
Show resolved
Hide resolved
refactor keyboard shortcut helper functions
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.
This looks and works great on Mac now, although there is a conflict that needs to be resolved before this can be merged
The conflict has been resolved. |
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.
That's quite the refactor
Description
Closes #6734
This PR adds more keyboard shortcuts to the Lexical Playground with a new plugin called
ShortcutsPlugin
to improve keyboard accessibility and user experience.Changes Made
ShortcutsPlugin
to handle all keyboard shortcuts in one place and make adding more shortcuts in the future easier. (This doesn't include some existing shortcuts like, bold and italic which are implemented at the lower level.)ToolbarContext
to manage the toolbar state which is shared between theToolbarPlugin
and theShortcutsPlugin
ToolbarPlugin
to theShortcutsPlugin
.ToolbarPlugin.tsx
to a new fileutils.ts
to be shared between theToolbarPlugin
and theShortcutsPlugin
.Choices Made
The issue was intended to add the keyboard shortcuts from MS Word, however, certain key combinations are reserved for browser usage and cannot be intercepted by client-side JavaScript, even if
event.preventDefault()
is called. (Ref: Chromium Issue 41081444). This is why we have chosen to use key bindings from well-known applications like Google Docs, Tiptap, and Slack, which are web-native applications. This choice ensures that users familiar with these applications will find the shortcuts intuitive and easy to use.Note
Test plan
End-to-end tests have been added for the new keyboard shortcuts.
Acknowledgement
@etrepum for his guidance and letting me work on this feature.
@BennyAlex for creating this useful feature request.