How I can separate document change events?

Answered

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?

 

0
3 comments


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.

 

 

0

Hi,

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.

0

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

0

Please sign in to leave a comment.