How I can separate document change events?


Hello! I'm trying to get code change events for the document, but the listener is capturing events for changing the file name. How can I separate these two types of events?


 editor.document.addDocumentListener(object : DocumentListener {
                    override fun documentChanged(event: DocumentEvent) {
                        // catch code changes — OK
                        // catch rename document — NOT OK

How I can recognize event types?



I found a heuristic in which, when changing the file name, FileDocumentManager.getInstance().getFile(editor.document) returns null.

But this looks like a dirty hack.





I tried to reproduce it, and it doesn't capture changing a file name. Are you sure that you don't change, e.g. class name, which results in renaming the class file and document content (class name in the code)? Or a similar case? If not, please share the code and describe exact steps to reproduce.


Karol Lewandowski thanks! Indeed, I double-checked after your response and noticed that I forgot to uncheck checkboxes in rename dialog.


Thank you so much


Please sign in to leave a comment.