devforth/painterro

Text element clone does not get cleared

nikhilmandlik opened this issue · 4 comments

Describe the bug
openmct is using "painterro": "^1.2.56" (Related bug in openmct: nasa/openmct#4019)

when a text filed is added it adds input element to document.body

Painterro version
"painterro": "^1.2.56",
but looks like latest version also has same issue.

To Reproduce
Steps to reproduce the behavior:

  1. run Painterro locally using npm run dev
  2. go to localhost:3000
  3. select text (T)
  4. click on canvas and add some text to it
  5. click 'checkmark/apply'
  6. inspect dom elements and find 'ptro-text-tool-input' (document.querySelectorAll('.ptro-text-tool-input'))
  7. there are two elements instead of one

Expected behavior
added clone should cleanup.

Screenshots
Screen Shot 2021-07-13 at 5 09 21 PM

Browser
Google Chrome, MAC
Brave, MAC

there is issue with clone not removed from DOM,

document.body.appendChild(clone);

following apply() fixes this issue,

apply() {
    const origBorder = this.input.style.border;
    const scale = this.main.getScale();
    this.input.style.border = 'none';
    const inputClone = this.hiddenInputClone();
    html2canvas(inputClone, {
      backgroundColor: null,
      logging: false,
      scale,
      scrollX: 0,
      scrollY: 0,
    }).then((can) => {
      this.ctx.drawImage(can, this.scaledCord[0], this.scaledCord[1]);
      this.input.style.border = origBorder;
      this.close();
      this.main.worklog.captureState();
      this.main.closeActiveTool();

      inputClone.remove();
    }).catch(e => {
      console.error(e);
      inputClone.remove();
    });
  }

Thanks a lot @nikhilmandlik , we will apply a fix

@nikhilmandlik Thanks for your issue, this was fixed in the 1.2.58 version

Thank you to the Painterro team for the super quick turnaround on this! We appreciate it.