Shortcuts
A command-line icon button in the activity bar. It opens a dialog that groups the shortcuts by History, Formatting, Blocks and Lists, with key labels for the visitor's platform.
Installation
This pattern is built from files in @intentui/editor. Install the editor, then copy the code above into a component of your own.
npx shadcn@latest add @intentui/editor
What's included
| Piece | Why it is here |
|---|---|
RichTextExtension | Lexical's rich text behavior. Every pattern needs it. |
InitialStateExtension | Applies the seeded content immediately, so the server and the client render the same. Leave it out if your editor starts empty. See Seeding initial content. |
ShortcutsExtension | Binds the keys and runs the actions. Remove it and the dialog still opens, but the custom shortcuts below stop working. |
HistoryExtension | Undo and redo. |
ListExtension, CheckListExtension | The numbered, bulleted and check list shortcuts. |
CodeExtension | The code block shortcut. |
TabIndentationExtension | Makes Tab indent. |
ShortcutPlugin | The button and dialog. It takes no props. |
ActivityBar | The strip that holds the button. See Activity bar. |
Removing ShortcutPlugin only removes the dialog. The shortcuts keep working. The dialog lists every shortcut the pattern registers, so if you drop an extension such as ListExtension, remove its rows from SHORTCUT_GROUPS too.
Customizing
Bindings live in the SHORTCUT_BINDINGS object in extensions/shortcuts-extension.ts, each as a key plus modifiers. Change a binding there and both the shortcut and the dialog label update. The dialog rows come from the SHORTCUT_GROUPS array in shortcut-plugin.tsx.
Shortcut reference
Use Cmd instead of Ctrl and Option instead of Alt on macOS, except where noted.
History and text
| Action | Shortcut |
|---|---|
| Undo | Ctrl Z |
| Redo | Ctrl Y, or Cmd Shift Z on macOS |
| Bold | Ctrl B |
| Italic | Ctrl I |
| Underline | Ctrl U |
| Strikethrough | Ctrl Shift X |
| Inline code | Ctrl Shift C |
| Subscript | Ctrl , |
| Superscript | Ctrl . |
| Lowercase | Ctrl Shift 1 |
| Uppercase | Ctrl Shift 2 |
| Title case | Ctrl Shift 3 |
| Clear formatting | Ctrl \ |
Lowercase, uppercase and title case use Ctrl on every platform, including macOS. Highlight has no shortcut.
Alignment and indent
| Action | Shortcut |
|---|---|
| Align left | Ctrl Shift L |
| Align center | Ctrl Shift E |
| Align right | Ctrl Shift R |
| Justify | Ctrl Shift J |
| Indent | Ctrl ] |
| Outdent | Ctrl [ |
Blocks and lists
| Action | Shortcut |
|---|---|
| Paragraph | Ctrl Alt 0 |
| Heading 1 | Ctrl Alt 1 |
| Heading 2 | Ctrl Alt 2 |
| Heading 3 | Ctrl Alt 3 |
| Quote | Ctrl Shift Q |
| Code block | Ctrl Alt C |
| Numbered list | Ctrl Shift 7 |
| Bulleted list | Ctrl Shift 8 |
| Check list | Ctrl Shift 9 |
Quote is Ctrl Shift Q on every platform, including macOS. A heading or quote shortcut on a block that already has that type does nothing. A list shortcut on a block that is already that list turns it back into a paragraph.
Other keys
| Key | What it does |
|---|---|
| Tab | Indents. Inside a code block it inserts a 2-space indent. |
| Arrow | At the start or end of a code block or columns block that is the first or last block, an arrow key creates a paragraph so you can move out. |
| Tab or Right | Accepts the autocomplete suggestion when one is shown. |
| Esc | Closes the link editor. |
Markdown shortcuts
Type these at the start of a line, then a space, to convert the block. They come from the transformers registered in editor.tsx, so they only work in editors that call registerMarkdownShortcuts. See Markdown shortcuts. The pattern above does not register them.
| Type | Result |
|---|---|
# to ###### | Heading 1 to 6 |
> | Quote |
- , * or + | Bulleted list |
1. | Numbered list |
[ ] or - [ ] | Check list ([x] for a checked item) |
```js then space | Code block, language optional |
---, *** or ___ | Divider |
| a | b | | Table row |
 | Image, converted when you type the closing ) |
:name: | Emoji, for example :smile: |
Inline formatting converts when you type the closing marker:
| Type | Result |
|---|---|
**text** or __text__ | Bold |
*text* or _text_ | Italic |
***text*** or ___text___ | Bold and italic |
~~text~~ | Strikethrough |
==text== | Highlight |
`text` | Inline code |
[text](url) | Link |
Menu triggers
| Type | Opens |
|---|---|
/ | Slash menu |
: | Emoji picker |
@ | Mention |
Related patterns
- Text format, Block format and Alignment and indent for the buttons behind these shortcuts.
- Markdown shortcuts for the typing shortcuts.
- History for undo and redo.