Skip to content

Commit

Permalink
Add keyboard shortcuts for superscript & subscript
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Oct 17, 2017
1 parent 8e88c3b commit 39f18db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ We support keyboard shortcuts inspired by the ones used in [Google Docs](https:/
| Underline | `Ctrl + U` | `⌘ + U` |
| Monospace (code) | `Ctrl + J` | `⌘ + J` |
| Strikethrough | `Ctrl + Shift + X` | `⌘ + Shift + X` |
| Superscript | `Ctrl + .` | `⌘ + .` |
| Subscript | `Ctrl + ,` | `⌘ + ,` |
| **Paragraph formatting (if enabled)** |||
| Increase list indentation | `Tab` | `Tab` |
| Decrease list indentation | `Shift + Tab` | `Shift + Tab` |
Expand Down
10 changes: 10 additions & 0 deletions lib/api/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ export default {
hasCommandModifier(e)
? INLINE_STYLE.UNDERLINE
: null;
case KEY_CODES['.']:
return isEnabledInline.SUPERSCRIPT &&
hasCommandModifier(e)
? INLINE_STYLE.SUPERSCRIPT
: null;
case KEY_CODES[',']:
return isEnabledInline.SUBSCRIPT &&
hasCommandModifier(e)
? INLINE_STYLE.SUBSCRIPT
: null;
case KEY_CODES[0]:
// Reverting to unstyled block is always available.
return (e.ctrlKey || e.metaKey) && e.altKey
Expand Down
10 changes: 10 additions & 0 deletions lib/api/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export const KEY_CODES = {
6: 54,
7: 55,
8: 56,
'.': 190,
',': 188,
};

export const KEYBOARD_SHORTCUTS = {
Expand Down Expand Up @@ -178,6 +180,14 @@ export const KEYBOARD_SHORTCUTS = {
other: 'Ctrl+Shift+X',
macOS: '⌘+Shift+X',
},
[INLINE_STYLE.SUPERSCRIPT]: {
other: 'Ctrl+.',
macOS: '⌘+.',
},
[INLINE_STYLE.SUBSCRIPT]: {
other: 'Ctrl+,',
macOS: '⌘+,',
},

[ENTITY_TYPE.LINK]: { other: 'Ctrl+K', macOS: '⌘+K' },

Expand Down

0 comments on commit 39f18db

Please sign in to comment.