UNPKG

@atlaskit/editor-plugin-selection

Version:

Selection plugin for @atlaskit/editor-core

36 lines 1.54 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({ selection, storedMarks }) { var _nodeBefore$marks, _nodeAfter$marks; if (!isTextSelection(selection) || !selection.empty) { return MarksSide.None; } const { nodeBefore, nodeAfter } = selection.$head; const leftMarks = (_nodeBefore$marks = nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.marks) !== null && _nodeBefore$marks !== void 0 ? _nodeBefore$marks : []; const 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, rightMarks, storedMarks }); }