add keyboardShortcut and enter command

This commit is contained in:
Philipp Kühn
2021-02-09 21:04:33 +01:00
parent e8232dd737
commit 2315357125
5 changed files with 102 additions and 46 deletions

View File

@@ -1,36 +1,8 @@
import { Command } from '../types'
/**
* Press Enter
* Trigger enter.
*/
export const enter = (): Command => ({
editor,
view,
tr,
dispatch,
}) => {
const keyCode = 13
const key = 'Enter'
const event = document.createEvent('Event')
event.initEvent('keydown', true, true)
// @ts-ignore
event.keyCode = keyCode
// @ts-ignore
event.key = key
// @ts-ignore
event.code = key
const capturedTransaction = editor.captureTransaction(() => {
view.someProp('handleKeyDown', f => f(view, event))
})
capturedTransaction?.steps.forEach(step => {
const newStep = step.map(tr.mapping)
if (newStep && dispatch) {
tr.step(newStep)
}
})
return true
export const enter = (): Command => ({ commands }) => {
return commands.keyboardShortcut('Enter')
}