How the CTRL+Z undo works ? (plugin)

Hi all, still trying to make a plugin, I try to insert a new element in dom. It’s work but When I do ctrl+z, nothing happen for that element. But works for others.

So,

  1. I tape a text “fljsdk”
  2. insert the following code (via a right click)

const a = cell.createEl(“a”);
a.innerText = “testfdsfs”;
range.insertNode(a);

3)I inserert something else. 'ffffff"
4) I do ctrl+Z…

What’s happen is that 3 is undo, 1 is undo but not 2. it’s like it not exist in the undomanager.
And it’s the same for all createEl I do…
I tried many things, but never worked. Any idea ? thanks.