add more core commands
This commit is contained in:
@@ -1,48 +1,36 @@
|
||||
import {
|
||||
newlineInCode,
|
||||
createParagraphNear,
|
||||
liftEmptyBlock,
|
||||
exitCode,
|
||||
deleteSelection,
|
||||
joinForward,
|
||||
joinBackward,
|
||||
selectNodeForward,
|
||||
selectNodeBackward,
|
||||
} from 'prosemirror-commands'
|
||||
import { undoInputRule } from 'prosemirror-inputrules'
|
||||
import { Extension } from '../Extension'
|
||||
|
||||
export const Keymap = Extension.create({
|
||||
name: 'keymap',
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
const handleBackspace = () => this.editor.commands.first(({ state, dispatch }) => [
|
||||
() => undoInputRule(state, dispatch),
|
||||
() => deleteSelection(state, dispatch),
|
||||
() => joinBackward(state, dispatch),
|
||||
() => selectNodeBackward(state, dispatch),
|
||||
const handleBackspace = () => this.editor.commands.first(({ commands }) => [
|
||||
() => commands.undoInputRule(),
|
||||
() => commands.deleteSelection(),
|
||||
() => commands.joinBackward(),
|
||||
() => commands.selectNodeBackward(),
|
||||
])
|
||||
|
||||
const handleDelete = () => this.editor.commands.first(({ state, dispatch }) => [
|
||||
() => deleteSelection(state, dispatch),
|
||||
() => joinForward(state, dispatch),
|
||||
() => selectNodeForward(state, dispatch),
|
||||
const handleDelete = () => this.editor.commands.first(({ commands }) => [
|
||||
() => commands.deleteSelection(),
|
||||
() => commands.joinForward(),
|
||||
() => commands.selectNodeForward(),
|
||||
])
|
||||
|
||||
return {
|
||||
Enter: () => this.editor.commands.first(({ commands, state, dispatch }) => [
|
||||
() => newlineInCode(state, dispatch),
|
||||
() => createParagraphNear(state, dispatch),
|
||||
() => liftEmptyBlock(state, dispatch),
|
||||
Enter: () => this.editor.commands.first(({ commands }) => [
|
||||
() => commands.newlineInCode(),
|
||||
() => commands.createParagraphNear(),
|
||||
() => commands.liftEmptyBlock(),
|
||||
() => commands.splitBlock(),
|
||||
]),
|
||||
'Mod-Enter': exitCode,
|
||||
'Mod-Enter': () => this.editor.commands.exitCode(),
|
||||
Backspace: () => handleBackspace(),
|
||||
'Mod-Backspace': () => handleBackspace(),
|
||||
Delete: () => handleDelete(),
|
||||
'Mod-Delete': () => handleDelete(),
|
||||
// we don’t need a custom `selectAll` for now
|
||||
// 'Mod-a': () => this.editor.selectAll(),
|
||||
// 'Mod-a': () => this.editor.commands.selectAll(),
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user