Transaction created in appendTransaction doesn't get undone

Hello, I am trying to create a plugin that adds an “edited” attribute to certain nodes if they get edited by the user. For that, I’m using the appendTransaction using a very similar approach to the prosemirror-tables package’s fixtables ( prosemirror-tables/src/fixtables.ts at 77e3cb272ce1f46ef7d3e66acc45f592209af250 · ProseMirror/prosemirror-tables · GitHub ).

I am able to set the “edited” attribute on the correct node by creating a new transaction and calling its setNodeAttribute method in appendTransaction, however the attribute is not removed when undoing the user changes. I return null if no

I was under the impression from all I’ve read so far in the docs and in the forums that an appendedTransaction is grouped to the undo history of the current transactions, but this doesn’t seem to be the case.

Did I misunderstand how appendTransaction works ?

Thanks in advance for any help you can give.

Are you sure you’re not seeing the appendtransaction hook run again after the undo? I tried to set up a scenario like you describe, but for me undoing works, in that it undoes the appended steps.

1 Like

That seems to be indeed what’s happening. Thank you very much. I didn’t expect the appendTransaction to get called on undo. Is there anyway to know if a transaction is being done as part of an undo ?

Nevermind; an undo transaction has a meta “history$“ which I can check for. Thanks again for your help.

prosemirror-history 1.5.0 has an isHistoryTransaction predicate. That’s more reliably than the meta property (which could potentially change).

1 Like