move commands again

This commit is contained in:
Philipp Kühn
2020-11-04 22:38:52 +01:00
parent ca0c3188f3
commit 6f3db0970f
59 changed files with 761 additions and 1066 deletions

View File

@@ -0,0 +1,52 @@
import {
newlineInCode,
createParagraphNear,
liftEmptyBlock,
exitCode,
deleteSelection,
joinForward,
joinBackward,
selectNodeForward,
selectNodeBackward,
} from 'prosemirror-commands'
import { undoInputRule } from 'prosemirror-inputrules'
import { createExtension } from '../Extension'
export const Keymap = createExtension({
addKeyboardShortcuts() {
const handleBackspace = () => this.editor.try(({ state, dispatch }) => [
() => undoInputRule(state, dispatch),
() => deleteSelection(state, dispatch),
() => joinBackward(state, dispatch),
() => selectNodeBackward(state, dispatch),
])
const handleDelete = () => this.editor.try(({ state, dispatch }) => [
() => deleteSelection(state, dispatch),
() => joinForward(state, dispatch),
() => selectNodeForward(state, dispatch),
])
return {
Enter: () => this.editor.try(({ commands, state, dispatch }) => [
() => newlineInCode(state, dispatch),
() => createParagraphNear(state, dispatch),
() => liftEmptyBlock(state, dispatch),
() => commands.splitBlock(),
]),
'Mod-Enter': exitCode,
Backspace: () => handleBackspace(),
'Mod-Backspace': () => handleBackspace(),
Delete: () => handleDelete(),
'Mod-Delete': () => handleDelete(),
// we dont need a custom `selectAll` for now
// 'Mod-a': () => this.editor.selectAll(),
}
},
})
declare module '../Editor' {
interface AllExtensions {
Keymap: typeof Keymap,
}
}