@atlaskit/editor-plugin-highlight
Version:
Highlight plugin for @atlaskit/editor-core
31 lines (29 loc) • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.updatePaddingDecorations = void 0;
var _addPaddingDecorations = require("./add-padding-decorations");
/**
* Updates padding decorations in the specified range.
*/
var updatePaddingDecorations = exports.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 (0, _addPaddingDecorations.addPaddingDecorations)({
decorationSet: decorationSet,
state: state,
from: from,
to: to
});
};