UNPKG

@atlaskit/editor-plugin-selection

Version:

Selection plugin for @atlaskit/editor-core

34 lines 1.68 kB
import { isTextSelection } from '@atlaskit/editor-common/utils'; import { Mark } from '@atlaskit/editor-prosemirror/model'; import { MarksSide } from '../marks-side'; import { getInlineCodeCursorSide } from './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. */ export function getActiveMarksSide(_ref) { var _nodeBefore$marks, _nodeAfter$marks; var selection = _ref.selection, storedMarks = _ref.storedMarks; if (!isTextSelection(selection) || !selection.empty) { return 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 (Mark.sameSet(leftMarks, rightMarks)) { return MarksSide.None; } return getInlineCodeCursorSide({ leftMarks: leftMarks, rightMarks: rightMarks, storedMarks: storedMarks }); }