linkedom
linkedom copied to clipboard
Missing `splitText` on `Text` node
Hello!
Thanks for this amazing package!
I just miss the Text.splitText method.
In the meantime, I'm using this naive implementation :
dom.Text.prototype.splitText = function (offset) {
const [start, end] = (() => {
if (offset <= 0) return ['', this.data];
if (offset >= this.data.length) return [this.data, ''];
return [
this.data.substring(0, offset),
this.data.substring(offset),
];
})();
const newNode = dom.document.createTextNode(end);
this.parentNode.insertBefore(newNode, this.nextSibling);
this.data = start;
return newNode;
};
Thanks.
why not filing a PR instead? I don't mind naive implementations as long as not obtrusive for the fast-path use case and working reasonably well (and code-covered, of course).
not enough interest in this, closing until PR available.