How can I get Position from Document before the change?

I want to get change’s range by Position (row & column) like v5 to integrate tree-sitter.
Migration guide and similar topic asked before says I can easily calculate Position value with doc.lineAt, but that doesn’t works when I try to get Position from document before the change.

I get error like: Invalid position 12 in document of length 11 every time when I delete some texts.

Are there any way to get last document’s change range?

If you have the transaction, its changes property gives you precisely this. If you don’t, then no, there’s no concept of a ‘last document’.

Thank you for your fast help, that worked.
Now what I’m curious is: are there cases when transaction is empty?
Is accessing ViewUpdate.transactions[0].startState.doc on EditorView.updateListener.of() stable enough than simply migrating to v5?

Yes, ViewUpdate.transactions may be empty. It may also hold more than one transaction. So loop over them or use ViewUpdate.changes, which combines them into a single changeset.