@atlaskit/editor-plugin-code-block-advanced
Version:
CodeBlockAdvanced plugin for @atlaskit/editor-core
31 lines (30 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createPlugin = void 0;
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
var _lazyCodeBlockAdvanced = require("../nodeviews/lazyCodeBlockAdvanced");
var _shiftArrowKeyWorkaround = require("./shiftArrowKeyWorkaround");
var createPlugin = exports.createPlugin = function createPlugin(props) {
return new _safePlugin.SafePlugin({
props: {
nodeViews: {
codeBlock: (0, _lazyCodeBlockAdvanced.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: function handleKeyDown(view, event) {
if (!(event instanceof KeyboardEvent)) {
return false;
}
if (event.key === 'ArrowUp' && event.shiftKey) {
return (0, _shiftArrowKeyWorkaround.shiftArrowUpWorkaround)(view, event);
} else if (event.key === 'ArrowDown' && event.shiftKey) {
return (0, _shiftArrowKeyWorkaround.shiftArrowDownWorkaround)(view, event);
}
}
}
});
};