UNPKG

@atlaskit/editor-plugin-code-block-advanced

Version:

CodeBlockAdvanced plugin for @atlaskit/editor-core

25 lines 1.05 kB
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import { lazyCodeBlockView } from '../nodeviews/lazyCodeBlockAdvanced'; import { shiftArrowDownWorkaround, shiftArrowUpWorkaround } from './shiftArrowKeyWorkaround'; export const createPlugin = props => { return new SafePlugin({ props: { nodeViews: { codeBlock: lazyCodeBlockView(props) }, // Custom selection behaviour to fix issues with codeblocks with Shift + Arrow{Up || Down} // These issues are also present in the prosemirror codemirror example and @marijnh suggests to // use custom event handlers: https://github.com/ProseMirror/website/issues/83 handleKeyDown(view, event) { if (!(event instanceof KeyboardEvent)) { return false; } if (event.key === 'ArrowUp' && event.shiftKey) { return shiftArrowUpWorkaround(view, event); } else if (event.key === 'ArrowDown' && event.shiftKey) { return shiftArrowDownWorkaround(view, event); } } } }); };