UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

33 lines (32 loc) 1.11 kB
import { base, keyName } from 'w3c-keyname'; import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap'; import { SafePlugin } from '../safe-plugin'; /** * A workaround for mostly Cyrillic but should have a positive affect * on other languages / layouts. Attempts a similar approach to OS X. * @see ED-7310 * @see https://github.com/ProseMirror/prosemirror/issues/957 * @param bindings */ export function keymap(bindings) { return new SafePlugin({ props: { handleKeyDown: function handleKeyDown(view, event) { var name = keyName(event); var keyboardEvent = event; if (event.ctrlKey && name.length === 1 && // Check the unicode of the character to // assert that its not an ASCII character. // These are characters outside Latin's range. /[^\u0000-\u007f]/.test(name)) { keyboardEvent = new KeyboardEvent('keydown', { key: base[event.keyCode], code: event.code, ctrlKey: true }); } return keydownHandler(bindings)(view, keyboardEvent); } } }); }