UNPKG

@atlaskit/editor-plugin-highlight

Version:

Highlight plugin for @atlaskit/editor-core

25 lines (24 loc) 968 B
import { addPaddingDecorations } from './add-padding-decorations'; /** * Updates padding decorations in the specified range. */ export var updatePaddingDecorations = function updatePaddingDecorations(_ref) { var prevDecorationSet = _ref.decorationSet, state = _ref.state, start = _ref.start, end = _ref.end; // First remove any decorations within the range // Note that it finds all decorations in the set which touch the given range (including decorations that start or end directly at the boundaries) var toRemove = prevDecorationSet.find(start, end); var decorationSet = prevDecorationSet.remove(toRemove); // Expand the range by 1 on each side to catch adjacent text nodes // that may need padding decorations added/removed var from = Math.max(0, start - 1); var to = Math.min(state.doc.content.size, end + 1); return addPaddingDecorations({ decorationSet: decorationSet, state: state, from: from, to: to }); };