Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Highlighting related terms in a text editor
Highlighting related terms in a text editor [message #326143] Sat, 08 March 2008 11:01 Go to next message
Eclipse UserFriend
Originally posted by: mthibberd.gmail.com

I am looking to implement a feature in a text editor that highlights (with
a background colour) related terms in a text editor. Something very
similar to the way the JavaEditor highlights all variable occurrences in
Grey when the cursor is at the declaration.

Does anyone know where the code to do this is in JDT, or have any idea
where to start?

For background, the text editor I am working with extends:
org.eclipse.ui.editors.text.TextEditor and has a SourceViewerConfiguration
that does some syntax highlighting for the language.

I have been looking at setHighlightRange(), but I:
a) can't get it to work yet
b) not sure if it is even the right functionality for what I am trying to
do

Any pointers would be appreciated.
Re: Highlighting related terms in a text editor [message #326165 is a reply to message #326143] Mon, 10 March 2008 08:43 Go to previous message
Eclipse UserFriend
Originally posted by: valere.fedronic.ext.streamezzo.com

Hi,

You must create your own annotation type
(org.eclipse.ui.editors.annotationTypes), and define the presentation
(org.eclipse.ui.editors.markerAnnotationSpecification).
E.g. 'org.eclipse.jdt.ui.occurrences' in the plugin.xml of the jdt.ui
plugin.

And then every time you find an occurrence of the text you try to match,
you just have to add an annotation :

IAnnotationModel#addAnnotation(new Annotation("custom.occurrences",
false, message), new Position(offset,length));

(Of course, it's a little harder than that, you will have to
update/remove these annotation when needed)

The java occurence finder code is located in the JavaEditor.class
(#updateOccurrenceAnnotations(),#installOccurrencesFinder
JavaEditor$OccurrencesFinderJob) etc...


Valère.

PS:
The setHighlightRange method is used to shade part of the vertical ruler
corresponding to the current text selection.




Mark Hibberd a écrit :
> I am looking to implement a feature in a text editor that highlights
> (with a background colour) related terms in a text editor. Something
> very similar to the way the JavaEditor highlights all variable
> occurrences in Grey when the cursor is at the declaration.
>
> Does anyone know where the code to do this is in JDT, or have any idea
> where to start?
>
> For background, the text editor I am working with extends:
> org.eclipse.ui.editors.text.TextEditor and has a
> SourceViewerConfiguration that does some syntax highlighting for the
> language.
> I have been looking at setHighlightRange(), but I:
> a) can't get it to work yet
> b) not sure if it is even the right functionality for what I am trying
> to do
>
> Any pointers would be appreciated.
>
Previous Topic:How is IPackageDeclaration#getSourceRange supposed to work?
Next Topic:Showing deleted file from local history
Goto Forum:
  


Current Time: Thu Jul 25 20:19:31 GMT 2024

Powered by FUDForum. Page generated in 0.02846 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top