I just verified a case I put into a comment on #6483: renaming an image file inside a collapsed folder opens the folder.
The code on this branch does not yet address that case, but I think if you remove the parentWasClosed variable and just do an else block in line 1771 you may fix that case too. By making sure the folders closed state is maintained.