This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/app/components/Editor/plugins/KeyboardShortcuts.js

36 lines
969 B
JavaScript

// @flow
import { Change } from 'slate';
import { isModKey } from '../utils';
export default function KeyboardShortcuts() {
return {
onKeyDown(ev: SyntheticKeyboardEvent, change: Change) {
if (!isModKey(ev)) return null;
switch (ev.key) {
case 'b':
return this.toggleMark(change, 'bold');
case 'i':
return this.toggleMark(change, 'italic');
case 'u':
return this.toggleMark(change, 'underlined');
case 'd':
return this.toggleMark(change, 'deleted');
case 'k':
return change.wrapInline({ type: 'link', data: { href: '' } });
default:
return null;
}
},
toggleMark(change: Change, type: string) {
const { value } = change;
// don't allow formatting of document title
const firstNode = value.document.nodes.first();
if (firstNode === value.startBlock) return;
change.toggleMark(type);
},
};
}