linkedom icon indicating copy to clipboard operation
linkedom copied to clipboard

Missing `splitText` on `Text` node

Open aloisdeniel opened this issue 3 years ago • 1 comments

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.

aloisdeniel avatar Aug 29 '22 06:08 aloisdeniel

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).

WebReflection avatar Aug 29 '22 10:08 WebReflection

not enough interest in this, closing until PR available.

WebReflection avatar Oct 21 '22 18:10 WebReflection