Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function onKeyDown(event, editor, next) {
debug('onKeyDown', { event })
const { value } = editor
const { document, selection } = value
const { start } = selection
const hasVoidParent = document.hasVoidParent(start.path, editor)
// COMPAT: In iOS, some of these hotkeys are handled in the
// `onNativeBeforeInput` handler of the `<content>` component in order to
// preserve native autocorrect behavior, so they shouldn't be handled here.
if (Hotkeys.isSplitBlock(event) && !IS_IOS) {
return hasVoidParent
? editor.moveToStartOfNextText()
: editor.splitBlock()
}
if (Hotkeys.isDeleteBackward(event) && !IS_IOS) {
return editor.deleteCharBackward()
}
if (Hotkeys.isDeleteForward(event) && !IS_IOS) {
return editor.deleteCharForward()
}
if (Hotkeys.isDeleteLineBackward(event)) {
return editor.deleteLineBackward()
}</content>
// Certain hotkeys have native editing behaviors in `contenteditable`
// elements which will editor the DOM and cause our value to be out of sync,
// so they need to always be prevented.
if (
!IS_IOS &&
(Hotkeys.isBold(event) ||
Hotkeys.isDeleteBackward(event) ||
Hotkeys.isDeleteForward(event) ||
Hotkeys.isDeleteLineBackward(event) ||
Hotkeys.isDeleteLineForward(event) ||
Hotkeys.isDeleteWordBackward(event) ||
Hotkeys.isDeleteWordForward(event) ||
Hotkeys.isItalic(event) ||
Hotkeys.isRedo(event) ||
Hotkeys.isSplitBlock(event) ||
Hotkeys.isTransposeCharacter(event) ||
Hotkeys.isUndo(event))
) {
event.preventDefault()
}
isUserActionPerformed = true
debug('onKeyDown', { event })
next()
}