Thanks for the answer, it works perfectly. I suppose that if i want to avoid this behaviour when a node is expanded, i just need to replace the code
(e.field !== "selected" && e.field !== "expanded")
I don't know if there is more events linked to navigation between nodes. I want to avoid the dirty state in this cases.