@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
27 lines • 1.1 kB
JavaScript
import { coerce, offsetRefs } from './schema-builder';
/**
* Replace the given range, or the selection if no range is given, with a text node containing the given string
*/
export function insertText(view, text, from, to) {
var pos = from;
text.split('').forEach(function (character, index) {
if (!view.someProp('handleTextInput', function (f) { return f(view, pos + index, pos + index, character); })) {
view.dispatch(view.state.tr.insertText(character, pos + index, pos + index));
}
});
}
/**
* Replace the current selection with the given content, which may be a fragment, node, or array of nodes.
*
* @returns refs from the inserted nodes, made relative to the document
* insertion position
*/
export function insert(view, content) {
var state = view.state;
var _a = state.selection, from = _a.from, to = _a.to;
var _b = coerce(content, state.schema), nodes = _b.nodes, refs = _b.refs;
var tr = state.tr.replaceWith(from, to, nodes);
view.dispatch(tr);
return offsetRefs(refs, from);
}
//# sourceMappingURL=transactions.js.map