How to refresh gutters

I’m writing an assembly language IDE and using a gutter to show the assembled address and bytecode. I can do this because, on every doc change (via EditorView.updateListener), I reassemble the file. The problem is that the gutter is always one keystroke behind. (The doc change results in new bytecode, but the view doesn’t update with this new bytecode until the next doc change.)

Is there a way to tell the view that it should refresh the gutter contents? The gutter API seems to be pull-based, with no way to push updates outside a doc change. Should I somehow dispatch an empty transaction spec?

Thank you!


1 Like

I also need a similar solution.

I was able to fix the one-keystroke-behind problem with:

lineMarkerChange: (update: ViewUpdate) => true,

but I don’t know how inefficient that is, or if that’s even a legit solution. It happens to work, but it’s not really based on the gutter data actually changing. I’d prefer to officially inform CM that the gutter needs to be refreshed.

1 Like

This solution also fixed my problem. Thanks for share. :clap:

Where are you keeping the address data? updateListener is almost certainly not the right way to recompute this—it runs after an update is finished, whereas if you do this in a state field or view plugin update method, you’ll be able to do the recomputation during the update, and avoid extra redraw cycles (which the lineMarkerChange solution is definitely going to cause).

Okay here’s what I did: I created a structure to hold the results of assembling the program; I made a state field for that; its update() function re-assembles the editor contents to make a new result; the EditorView.updateListener now updates non-editor webpage state from the assembly results.

Does that seem about right? Thank you for the help!

Yes, that sounds reasonable.