tiptap/docs/src/docPages/api/keyboard-shortcuts.md

103 lines
7.1 KiB
Markdown
Raw Normal View History

# Keyboard Shortcuts
2020-09-24 23:33:04 +08:00
Keyboard shortcuts may be strings like `'Shift-Control-Enter'`. Keys are based on the strings that can appear in `event.key`, concatenated with a `-`. There is a little tool called [keycode.info](https://keycode.info/), which shows the `event.key` interactively.
2020-09-24 21:10:44 +08:00
Use lowercase letters to refer to letter keys (or uppercase letters if you want shift to be held). You may use `Space` as an alias for the <code>&nbsp;</code>.
2020-09-24 21:10:44 +08:00
Modifiers can be given in any order. `Shift`, `Alt`, `Control` and `Cmd` are recognized. For characters that are created by holding shift, the `Shift` prefix is implied, and should not be added explicitly.
2020-09-24 21:10:44 +08:00
You can use `Mod` as a shorthand for `Cmd` on Mac and `Control` on other platforms.
2020-09-27 16:29:01 +08:00
## Table of Contents
2020-09-24 21:10:44 +08:00
## Overwrite keyboard shortcuts
```js
// 1. Import the extension
import BulletList from '@tiptap/extension-bullet-list'
// 2. Overwrite the keyboard shortcuts
2020-09-26 00:02:22 +08:00
const CustomBulletList = BulletList()
2020-09-24 21:10:44 +08:00
.keys(({ editor }) => ({
// ↓ your new keyboard shortcut
'Mod-l': () => editor.bulletList(),
}))
.create() // Dont forget that!
// 3. Add the custom extension to your editor
new Editor({
extensions: [
CustomBulletList(),
// …
]
})
```
## Predefined keyboard shortcuts
### Essentials
2020-09-24 23:27:26 +08:00
| Action | Windows/Linux | macOS |
| ------------------------ | --------------------- | ----------------- |
| Copy | `Control`&nbsp;`C` | `Cmd`&nbsp;`C` |
| Cut | `Control`&nbsp;`X` | `Cmd`&nbsp;`X` |
| Paste | `Control`&nbsp;`V` | `Cmd`&nbsp;`V` |
| Paste without formatting | `Control`&nbsp;`Shift`&nbsp;`V` | `Cmd`&nbsp;`Shift`&nbsp;`V` |
| Undo | `Control`&nbsp;`Z` | `Cmd`&nbsp;`Z` |
| Redo | `Control`&nbsp;`Shift`&nbsp;`Z` | `Cmd`&nbsp;`Shift`&nbsp;`Z` |
| Insert or edit link | `Control`&nbsp;`K` | `Cmd`&nbsp;`K` |
| Open link | `Alt`&nbsp;`Enter` | `Alt`&nbsp;`Enter` |
| Find | `Control`&nbsp;`F` | `Cmd`&nbsp;`F` |
| Find and replace | `Control`&nbsp;`H` | `Cmd`&nbsp;`Shift`&nbsp;`H` |
| Find again | `Control`&nbsp;`G` | `Cmd`&nbsp;`G` |
| Find previous | `Control`&nbsp;`Shift`&nbsp;`G` | `Cmd`&nbsp;`Shift`&nbsp;`G` |
| Repeat last action | `Control`&nbsp;`Y` | `Cmd`&nbsp;`Y` |
| Add a line break | `Shift`&nbsp;`Enter` | `Shift`&nbsp;`Enter` |
2020-09-24 21:10:44 +08:00
### Text Formatting
2020-09-24 23:27:26 +08:00
| Action | Windows/Linux | macOS |
| --------------------- | --------------------------------------------- | ----------------- |
| Bold | `Control`&nbsp;`B` | `Cmd`&nbsp;`B` |
| Italicize | `Control`&nbsp;`I` | `Cmd`&nbsp;`I` |
| Underline | `Control`&nbsp;`U` | `Cmd`&nbsp;`U` |
| Strikethrough | `Alt`&nbsp;`Shift`&nbsp;`5` | `Cmd`&nbsp;`Shift`&nbsp;`X` |
| Superscript | `Control`&nbsp;`.` | `Cmd`&nbsp;`.` |
| Subscript | `Control`&nbsp;`,` | `Cmd`&nbsp;`,` |
| Copy text formatting | `Control`&nbsp;`Alt`&nbsp;`C` | `Cmd`&nbsp;`Alt`&nbsp;`C` |
| Paste text formatting | `Control`&nbsp;`Alt`&nbsp;`V` | `Cmd`&nbsp;`Alt`&nbsp;`V` |
| Clear text formatting | `Control`&nbsp;<code>\</code><br>`Control`&nbsp;`Space` | `Cmd`&nbsp;`\` |
| Increase font size | `Control`&nbsp;`Shift`&nbsp;`>` | `Cmd`&nbsp;`Shift`&nbsp;`>` |
| Decrease font size | `Control`&nbsp;`Shift`&nbsp;`<` | `Cmd`&nbsp;`Shift`&nbsp;`<` |
2020-09-24 21:10:44 +08:00
### Paragraph Formatting
2020-09-24 23:27:26 +08:00
| Action | Windows/Linux | macOS |
| ------------------------------ | --------------------- | --------------------- |
| Increase paragraph indentation | `Control`&nbsp;`]` | `Cmd`&nbsp;`]` |
| Decrease paragraph indentation | `Control`&nbsp;`[` | `Cmd`&nbsp;`[` |
| Apply normal text style | `Control`&nbsp;`Alt`&nbsp;`0` | `Cmd`&nbsp;`Alt`&nbsp;`0` |
| Apply heading style 1 | `Control`&nbsp;`Alt`&nbsp;`1` | `Cmd`&nbsp;`Alt`&nbsp;`1` |
| Apply heading style 2 | `Control`&nbsp;`Alt`&nbsp;`2` | `Cmd`&nbsp;`Alt`&nbsp;`2` |
| Apply heading style 3 | `Control`&nbsp;`Alt`&nbsp;`3` | `Cmd`&nbsp;`Alt`&nbsp;`3` |
| Apply heading style 4 | `Control`&nbsp;`Alt`&nbsp;`4` | `Cmd`&nbsp;`Alt`&nbsp;`4` |
| Apply heading style 5 | `Control`&nbsp;`Alt`&nbsp;`5` | `Cmd`&nbsp;`Alt`&nbsp;`5` |
| Apply heading style 6 | `Control`&nbsp;`Alt`&nbsp;`6` | `Cmd`&nbsp;`Alt`&nbsp;`6` |
| Left align | `Control`&nbsp;`Shift`&nbsp;`L` | `Cmd`&nbsp;`Shift`&nbsp;`L` |
| Center align | `Control`&nbsp;`Shift`&nbsp;`E` | `Cmd`&nbsp;`Shift`&nbsp;`E` |
| Right align | `Control`&nbsp;`Shift`&nbsp;`R` | `Cmd`&nbsp;`Shift`&nbsp;`R` |
| Justify | `Control`&nbsp;`Shift`&nbsp;`J` | `Cmd`&nbsp;`Shift`&nbsp;`J` |
| Numbered list | `Control`&nbsp;`Shift`&nbsp;`7` | `Cmd`&nbsp;`Shift`&nbsp;`7` |
| Bulleted list | `Control`&nbsp;`Shift`&nbsp;`8` | `Cmd`&nbsp;`Shift`&nbsp;`8` |
| Move paragraph up | `Control`&nbsp;`Shift`&nbsp;`↑` | `Control`&nbsp;`Shift`&nbsp;`↑` |
| Move paragraph down | `Control`&nbsp;`Shift`&nbsp;`↓` | `Control`&nbsp;`Shift`&nbsp;`↓` |
2020-09-24 21:10:44 +08:00
### Text Selection
2020-09-24 23:27:26 +08:00
| Action | Windows/Linux | macOS |
| ------------------------------------------------- | --------------------- | ----------------- |
| Select all | `Control`&nbsp;`A` | `Cmd`&nbsp;`A` |
| Extend selection one character to left | `Shift`&nbsp;`←` | `Shift`&nbsp;`←` |
| Extend selection one character to right | `Shift`&nbsp;`→` | `Shift`&nbsp;`→` |
| Extend selection one line up | `Shift`&nbsp;`↑` | `Shift`&nbsp;`↑` |
| Extend selection one line down | `Shift`&nbsp;`↓` | `Shift`&nbsp;`↓` |
| Extend selection one paragraph up | `Alt`&nbsp;`Shift`&nbsp;`↑` | `Alt`&nbsp;`Shift`&nbsp;`↑` |
| Extend selection one paragraph down | `Alt`&nbsp;`Shift`&nbsp;`↓` | `Alt`&nbsp;`Shift`&nbsp;`↓` |
| Extend selection to the beginning of the document | `Control`&nbsp;`Shift`&nbsp;`↑` | `Cmd`&nbsp;`Shift`&nbsp;`↑` |
| Extend selection to the end of the document | `Control`&nbsp;`Shift`&nbsp;`↓` | `Cmd`&nbsp;`Shift`&nbsp;`↓` |