@atlaskit/editor-plugin-selection
Version:
Selection plugin for @atlaskit/editor-core
40 lines (39 loc) • 1.85 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getActiveMarksSide = getActiveMarksSide;
var _utils = require("@atlaskit/editor-common/utils");
var _model = require("@atlaskit/editor-prosemirror/model");
var _marksSide = require("../marks-side");
var _inlineCodeSide = require("./inline-code-side");
/**
* Will determine which side of the current selection the mark-boundary-cursor should
* favour / point towards, based on which marks are currently active and which marks
* are applied to the nodes to the left and right side of the current selection.
*
* @param {Selection} options.selection - The current selection.
* @param {readonly Mark[] | null} options.storedMarks - Current stored marks, if any.
* @returns {MarksSide} - The side (left -1, right 1, or none 0) the mark-boundary-cursor should favour.
*/
function getActiveMarksSide(_ref) {
var _nodeBefore$marks, _nodeAfter$marks;
var selection = _ref.selection,
storedMarks = _ref.storedMarks;
if (!(0, _utils.isTextSelection)(selection) || !selection.empty) {
return _marksSide.MarksSide.None;
}
var _selection$$head = selection.$head,
nodeBefore = _selection$$head.nodeBefore,
nodeAfter = _selection$$head.nodeAfter;
var leftMarks = (_nodeBefore$marks = nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.marks) !== null && _nodeBefore$marks !== void 0 ? _nodeBefore$marks : [];
var rightMarks = (_nodeAfter$marks = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.marks) !== null && _nodeAfter$marks !== void 0 ? _nodeAfter$marks : [];
if (_model.Mark.sameSet(leftMarks, rightMarks)) {
return _marksSide.MarksSide.None;
}
return (0, _inlineCodeSide.getInlineCodeCursorSide)({
leftMarks: leftMarks,
rightMarks: rightMarks,
storedMarks: storedMarks
});
}