UNPKG

@atlaskit/editor-plugin-selection-marker

Version:

Selection marker plugin for @atlaskit/editor-core.

50 lines (48 loc) • 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.selectionDecoration = void 0; var _state = require("@atlaskit/editor-prosemirror/state"); var _view = require("@atlaskit/editor-prosemirror/view"); var _fg = require("@atlaskit/platform-feature-flags/fg"); var decorationStyle = "\n background-color: ".concat("var(--ds-background-neutral, #0515240F)", ";\n "); var decorationHighlightStyle = "\n background-color: ".concat("var(--ds-background-accent-blue-subtlest, #E9F2FE)", ";\n border-bottom: ", "var(--ds-border-width-selected, 2px)", " solid ", "var(--ds-background-accent-blue-subtler, #CFE1FD)", ";\n "); /** * A node-selected inline atom keeps its own selected-node styling instead of the marker. */ var isMarkableInlineAtom = function isMarkableInlineAtom(node, selection) { return node.isInline && node.isAtom && !(selection instanceof _state.NodeSelection && selection.node === node); }; var selectionDecoration = exports.selectionDecoration = function selectionDecoration(doc, selection, isHighlight) { var selectionDecorations = []; var style = isHighlight ? decorationHighlightStyle : decorationStyle; var shouldMarkInlineAtoms = (0, _fg.fg)('platform_editor_selection_marker_blur_fix'); doc.nodesBetween(selection.from, selection.to, function (currentNode, nodePos) { if (!currentNode.isText) { if (shouldMarkInlineAtoms && isMarkableInlineAtom(currentNode, selection)) { selectionDecorations.push(_view.Decoration.node(nodePos, nodePos + currentNode.nodeSize, { style: style, 'data-testid': 'selection-marker-inline-node', 'data-selection-marker': '' })); } return true; } var decorationFrom = selection.from; var decorationTo = selection.to; if (nodePos > selection.from) { decorationFrom = nodePos; } if (nodePos + currentNode.nodeSize < selection.to) { decorationTo = nodePos + currentNode.nodeSize; } selectionDecorations.push(_view.Decoration.inline(decorationFrom, decorationTo, { style: style, 'data-testid': 'selection-marker-selection', 'data-selection-marker': '' })); return true; }); return selectionDecorations; };