Listening for changes to FileEditor and re-rendering preview when using TextEditorWithPreview

I am building a plugin that would open YAML files of specific suffix in a TextEditorWithPreview. In the preview panel, I am rendering a visual representation of my bespoke YAML using JCEF. I am trying to make the preview re-render whenever the text in the editor panel is changed.

By studying MarkdownPreviewFileEditor, I have discovered that I should be using a DocumentListener to subscribe to modifications to the file. However, what I am finding is that the events are not debounced and thus cause inordinate number of events to be fired from my plugin.

Can you guide me in the right direction here?

Thanks.

It looks like MarkdownUpdateHandler performs its own debouncing.

I’ll be curious to hear otherwise, but I imagine you’re going to need to do the same, using document change events to know that your preview is dirty, and then having some wait time after the last change has been received before actually re-rendering.

I’ve had to do the same thing in a few places in my own plugin. It’s generally pretty simple to implement.

3 Likes