UndoRefactoringElementListener.undoElementMovedOrRenamed is not called on undo of a file move
Answered
I implement RefactoringElementListenerProvider to listen to rename and move of a file or a directory within the opened project.
The steps:
- Select a file and move it to a folder by dragging it with mouse
- RefactoringElementAdapter.elementRenamedOrMoved is called
- Press Ctrl+Z to undo the move and confirm in the Undo dialog
- UndoRefactoringElementListener.undoElementMovedOrRenamed is not called
Why RefactoringElementAdapter.elementRenamedOrMoved work on a file move, but UndoRefactoringElementListener.undoElementMovedOrRenamed doesn't work on undo the file move?
Please sign in to leave a comment.
Hi Maksim,
It's hard to help without more details. I suggest finding usages of UndoRefactoringElementListener.undoElementMovedOrRenamed in the platform code and setting breakpoints around to find out why it is not called in your context. If this approach doesn't work for you, please provide a minimum reproducible plugin example, test project and detailed steps to reproduce.
Hi Karol,
I did try to debug the code before posting the question here. Unfortunately, the code is pretty complicated, I thought maybe here I get an answer earlier, because the cause may be the design.
Here is a repo with the minimal plugin implementing the whole thing, see https://github.com/KMax/undoElementMovedOrRenamed-not-called-on-undo-file-move.
The steps to reproduce the issue:
elementRenamedOrMoved: PsiFile(plain text):<file name>
undoElementMovedOrRenamed: PsiFile(plain text):<file name>, …
elementRenamedOrMoved: PsiFile(plain text):<file name>
undoElementMovedOrRenamed
is not called, although I expect it to be called as in the case of rename.I guess, the cause is somewhere in
MoveFilesOrDirectoriesProcessor
.RenameProcess
, which is also a subclass ofBaseRefactoringProcessor
, callsRenameUtil.registerUndoableRename
, butMoveFilesOrDirectoriesProcessor
doesn't seem to have a similar call.Okay, after more debugging, my conclusion is that
MoveFilesOrDirectoriesProcessor
(or any other processor which would handle the move refactoring) does not create anUndoableAction
which would callundoElementMovedOrRenamed
method.I opened a bug report, see https://youtrack.jetbrains.com/issue/IDEA-333312/MoveFilesOrDirectoriesProcessor-does-not-call-undoElementMovedOrRenamed.