@atlaskit/editor-plugin-selection
Version:
Selection plugin for @atlaskit/editor-core
65 lines (62 loc) • 3.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = keymapPlugin;
var _keymaps = require("@atlaskit/editor-common/keymaps");
var _selection = require("@atlaskit/editor-common/selection");
var _commands = require("@atlaskit/editor-prosemirror/commands");
var _keymap = require("@atlaskit/editor-prosemirror/keymap");
var _actions = require("./gap-cursor/actions");
var _direction = require("./gap-cursor/direction");
function keymapPlugin() {
var map = {};
(0, _keymaps.bindKeymapWithCommand)(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
_keymaps.insertNewLine.common, function (state, dispatch, view) {
var isInGapCursor = state.selection instanceof _selection.GapCursorSelection;
// Only operate in gap cursor
if (!isInGapCursor) {
return false;
}
return (0, _commands.createParagraphNear)(state, dispatch);
}, map);
(0, _keymaps.bindKeymapWithCommand)(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
_keymaps.moveLeft.common, function (state, dispatch, view) {
var endOfTextblock = view ? view.endOfTextblock.bind(view) : undefined;
return (0, _actions.arrow)(_direction.Direction.LEFT, endOfTextblock)(state, dispatch, view);
}, map);
(0, _keymaps.bindKeymapWithCommand)(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
_keymaps.moveRight.common, function (state, dispatch, view) {
var endOfTextblock = view ? view.endOfTextblock.bind(view) : undefined;
return (0, _actions.arrow)(_direction.Direction.RIGHT, endOfTextblock)(state, dispatch);
}, map);
(0, _keymaps.bindKeymapWithCommand)(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
_keymaps.moveUp.common, function (state, dispatch, view) {
var endOfTextblock = view ? view.endOfTextblock.bind(view) : undefined;
return (0, _actions.arrow)(_direction.Direction.UP, endOfTextblock)(state, dispatch);
}, map);
(0, _keymaps.bindKeymapWithCommand)(
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
_keymaps.moveDown.common, function (state, dispatch, view) {
var endOfTextblock = view ? view.endOfTextblock.bind(view) : undefined;
return (0, _actions.arrow)(_direction.Direction.DOWN, endOfTextblock)(state, dispatch);
}, map);
// default PM's Backspace doesn't handle removing block nodes when cursor is after it
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, (0, _actions.deleteNode)(_direction.Direction.BACKWARD), map);
// handle Delete key (remove node after the cursor)
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(0, _keymaps.bindKeymapWithCommand)(_keymaps.deleteKey.common, (0, _actions.deleteNode)(_direction.Direction.FORWARD), map);
return (0, _keymap.keymap)(map);
}