Search code examples
eclipse-plugin

Eclipse custom text editor update syntax highlighting


I am writing an Eclipse plugin (Indigo/Juno) that contains a text editor for a custom text format. I am following the tutorial here: http://www.realsolve.co.uk/site/tech/jface-text.php

So far I have everything working. Eclipse will use my editor to edit files. I have partitioning, damaging, repairing, syntax highlighting all working.

I added a preferences page with color pickers to control syntax highlighting. It works mostly correct. If I update the colors, the editor uses them the next time I open or reopen a file.

How do I get an editor tab to update itself without opening a new one? The built-in JDT Java editor does this, but so far I have not been able to decipher how (it is a very large and complex editor).

I gather that I need to create a preferences listener (http://www.vogella.com/articles/EclipsePreferences/article.html). I have done this and can verify that my listener code is being invoked when I set a breakpoint in it.

The missing piece is the wiring between the listener and reinitializing the editor. I have tried reconstructing the partitioning logic, the color logic, the damager/repairer, etc. but nothing seems to work. It either does nothing I can see or at worst will corrupt the display until I scroll the current text out of view to repaint it... with the old colors.

Any ideas?


Solution

  • I think SourceViewer.invalidatePresentation() needs to be called.