@atlaskit/editor-plugin-selection-marker
Version:
Selection marker plugin for @atlaskit/editor-core.
25 lines • 1.23 kB
JavaScript
import { Decoration } from '@atlaskit/editor-prosemirror/view';
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 ");
export var selectionDecoration = function selectionDecoration(doc, selection, isHighlight) {
var selectionDecorations = [];
doc.nodesBetween(selection.from, selection.to, function (currentNode, nodePos) {
if (!currentNode.isText) {
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(Decoration.inline(decorationFrom, decorationTo, {
style: isHighlight ? decorationHighlightStyle : decorationStyle,
'data-testid': 'selection-marker-selection'
}));
return true;
});
return selectionDecorations;
};