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

[lexical-playground] Feature: Add more keyboard shortcuts #6754

Merged
merged 11 commits into from
Nov 6, 2024

Conversation

bedre7
Copy link
Contributor

@bedre7 bedre7 commented Oct 22, 2024

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

  • Added 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.)
  • Created a new ToolbarContext to manage the toolbar state which is shared between the ToolbarPlugin and the ShortcutsPlugin
  • Moved existing Insert Link shortcut listener from the ToolbarPlugin to the ShortcutsPlugin.
  • Moved common functions from ToolbarPlugin.tsx to a new file utils.ts to be shared between the ToolbarPlugin and the ShortcutsPlugin.
  • Added title attribute and shortcut labels to the toolbar items to show the newly added keyboard shortcuts.
  • Added end-to-end tests for the new keyboard shortcuts.

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

  1. Some shortcuts might not work for all languages or keyboards.
  2. The shortcuts have been added to the Playground only, so users can modify them as needed for their own applications.

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.

Copy link

vercel bot commented Oct 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2024 10:28pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2024 10:28pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 22, 2024
@bedre7 bedre7 closed this Oct 22, 2024
Copy link

github-actions bot commented Oct 22, 2024

size-limit report 📦

Path Size
lexical - cjs 29.92 KB (0%)
lexical - esm 29.78 KB (0%)
@lexical/rich-text - cjs 38.57 KB (0%)
@lexical/rich-text - esm 31.63 KB (0%)
@lexical/plain-text - cjs 37.22 KB (0%)
@lexical/plain-text - esm 28.94 KB (0%)
@lexical/react - cjs 40.33 KB (0%)
@lexical/react - esm 33.06 KB (0%)

@bedre7 bedre7 changed the title Feature/add keyboard shortcuts [Do not merge] Feature/add keyboard shortcuts Oct 22, 2024
@bedre7 bedre7 reopened this Oct 22, 2024
@bedre7 bedre7 marked this pull request as draft October 22, 2024 12:41
add ShortcutsPlugin
add ToolbarContext to share state between ShortcutsPlugin and ToolbarPlugin
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Nov 2, 2024
etrepum
etrepum previously approved these changes Nov 2, 2024
Copy link
Collaborator

@etrepum etrepum left a 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.

refactor keyboard shortcut helper functions
etrepum
etrepum previously approved these changes Nov 5, 2024
Copy link
Collaborator

@etrepum etrepum left a 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

@bedre7
Copy link
Contributor Author

bedre7 commented Nov 5, 2024

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.

@bedre7 bedre7 requested a review from etrepum November 5, 2024 11:57
Copy link
Collaborator

@ivailop7 ivailop7 left a 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

@etrepum etrepum added this pull request to the merge queue Nov 6, 2024
Merged via the queue into facebook:main with commit b284bea Nov 6, 2024
40 checks passed
@etrepum etrepum mentioned this pull request Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Add keyboard shortcuts so the editor is much more accessible
4 participants