How to know new State's future Node's positions in advance?

Right now my application renders fine decoration widgets based on the paragraph node’s attribute from a plugin. The all paragraph node’s attribute’s value is changed altogether via context menu using transaction’s dispatch. So far all good. There a couple of scenarios where I am having trouble. When splitting a line, the current line should have a different node attribute value. I can achieve this by handling keydown, where I dispatch the attribute value change of the current line and the new line (second half of the previous line) automatically copies this attribute. But the problem lies with undo, where first undo merges back to a single line, but the attribute is not changed. Another undo will change the attribute. I wanted this to happen together, I know appendTransaction is there to help this scenario, but how I can find the position of the new line that is going to created. To picturize, see the examples below all “(…)” content is not editable and is rendered via decoration widget. The inside of “(…)” is the attribute value.

(ABC) Hello World

After pressing Enter key in the middle of the line, this is expected:

(XYZ) Hello
(XYZ) World

and undoing from this condition, should give me back:

(ABC) Hello World

but this is what is I get now:

(XYZ) Hello World

Another case is with drag and drop. Lets say have these lines:

(ABC) This
(DEF) is
(GHI) a
(JKL) test
(MNO) Drag & Drop here.

After dragging first two lines and dropping on the last line, anticipating:

(GHI) a
(JKL) test
(XYZ) Drag & Drop here.This
(XYZ) is

I use dragstart and handleDrop. But not sure how to change the attributes of these new dropped lines within one undo history ie with undo I should this:

(ABC) This
(DEF) is
(GHI) a
(JKL) test
(MNO) Drag & Drop here.

Need to know new State’s future Node’s positions in advance so that I can use it in appendTransaction?

Does any of this comes handy for these scenarios? https://prosemirror.net/docs/ref/#view.DecorationSet.map https://prosemirror.net/docs/ref/#transform.Mapping.map

Any quick guidance & insight into this is appreciated. Thanks for considering!

For changing the way splitting works, it’s best to bind a handler to enter with a higher precedence than the default handler, and make that handle the splitting entirely, so you create only a single transaction for it.