Undo/Redo with multiple operation as an atomic operation
Hi,
In my plugin, user can change the XML document through a UI and for every change in the XML document, I am modifying a json file in the background. As an example, when a new tag is added to the XML file, a json file is modified in the background.
At the moment I am performing this write operation within
WriteCommandAction.runWriteCommandAction(project, "Added Tag", null, () ->{});
method (write operation for both XML and json files happen within a single WriteCommandAction.). But sometimes when I undo/redo, only the XML document gets updated and JSON file does not get updated. Is there a way to bind write to XML and JSON files as an atomic operation, so that undo/redo will modify both files.
Please sign in to leave a comment.
> "a json file is modified in the background"
Do you mean in a separate thread? Do you use Document/PSI to modify the json file?
In the same thread thread and I use Jackson's ObjectMapper to modify the json file because as far as I know IDEA does not provide an API to modify json files
There is a Json plugin for IntelliJ Platform, but it's not built-in.
In order to get atomic undo (and actually any sort of undo) you need to either modify json file via Document, or via VfsUtil.saveText (they should be performed in the WriteCommandAction).
Hi Anton,
Thanks for the solution. I will use VfsUtil.SaveText and see if undo/redo works as intended in my case.
Further, am I correct to assume that all write operations done within a single WriteCommandAction is atomic?