Search code examples
eclipseeclipse-pluginselectionchanged

Get notified when cursor position changed in Eclipse TextEditor


I am developing a plugin to eclipse and I want to add some actions to the context menu. But actually I wanted to prepare results beforehead according to the text selection in the editor and just show them when the menu item will be selected. I followed that article http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html - all interfaces (ISelectionListener, ISelectionChangedListener etc) allow to handle the SelectionChanged event, but editor counts changing only when length of selection also changes - so the simple click in the editor doesn't fire the event, although I want to get the word (for example) as a selection if cursor is inside the word now and lenght is 0.

So the question is - what is the simpliest solution for traking down cursor position/offset/selections with zero lengh value changing?


Solution

  • In that case you have to use KeyListener and MouseListener as well. For e.g take a look at org.eclipse.jface.text.PaintManager, and it listens to all these events.