Ritro
Ritro

Reputation: 148

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?

Upvotes: 2

Views: 590

Answers (2)

Sunil Biswal
Sunil Biswal

Reputation: 11

If you are extending TextEditor you can override handleCursorPositionChanged() method to fire your event and use getCursorPosition() to get the cursor position as a String.

Upvotes: 1

Deepak Azad
Deepak Azad

Reputation: 7923

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.

Upvotes: 1

Related Questions