remove outmoded code from markdown widget hotkeys

This commit is contained in:
Shawn Erquhart 2017-12-14 11:52:25 -08:00
parent 99ee5e2f9a
commit 1608b5e52a

View File

@ -3,37 +3,6 @@ import { isHotkey } from 'is-hotkey';
export default onKeyDown;
/**
* Minimal re-implementation of Slate's undo/redo functionality, but with focus
* forced back into editor afterward.
*/
function changeHistory(change, type) {
/**
* Get the history for undo or redo (determined via `type` param).
*/
const { history } = change.value;
if (!history) return;
const historyOfType = history[`${type}s`];
/**
* If there is a next history item to apply, and it's valid, apply it.
*/
const next = historyOfType.first();
const historyOfTypeIsValid = historyOfType.size > 1
|| (next && next.length > 1)
|| (next && next[0] && next[0].type !== 'set_selection';
if (next && historyOfTypeIsValid) {
change[type]();
}
/**
* Always ensure focus is set.
*/
return change.focus();
}
function onKeyDown(event, change) {
const createDefaultBlock = () => {
return Block.create({
@ -70,26 +39,9 @@ function onKeyDown(event, change) {
}
if (isHotkey(`mod+${event.key}`, event)) {
/**
* Undo and redo work automatically with Slate, but focus is lost in certain
* actions. We override Slate's built in undo/redo here and force focus
* back to the editor each time.
*/
if (event.key === 'y') {
event.preventDefault();
return changeHistory(change, 'redo');
}
if (event.key === 'z') {
event.preventDefault();
return changeHistory(change, event.isShift ? 'redo' : 'undo');
}
const marks = {
b: 'bold',
i: 'italic',
u: 'underline',
s: 'strikethrough',
'`': 'code',
};