hata6502 / editorjs-style

Inline-style Tool for Editor.js
https://hata6502.github.io/editorjs-style/
MIT License
57 stars 4 forks source link

Add fake background #1

Open hata6502 opened 4 years ago

hata6502 commented 4 years ago

It doesn't work:

    const prevFakeBackGround = this.fakeBackground;

    this.fakeBackground = document.createElement('span');
    this.fakeBackground.style.backgroundColor = 'red';

    const range = selection.getRangeAt(0);

    this.fakeBackground.append(range.extractContents());

    if (prevFakeBackGround) {
      // TODO: unificate
      const clonedNodes = Array.from(prevFakeBackGround.childNodes).map((node) =>
        node.cloneNode(true)
      );

      clonedNodes.forEach((node) =>
      prevFakeBackGround?.parentNode?.insertBefore(node, prevFakeBackGround)
      );

      prevFakeBackGround.remove();
    }

    range.insertNode(this.fakeBackground);
    this.api.selection.expandToTag(this.fakeBackground);

Fake bacground is too complex.