Suggestion: highlight selected word

Posted 10 years ago by Avatar Erel Uziel
Several text editors and code editors have this great feature. When you select a word (any word) in the text, all identical words are highlighted.
This is very useful if for example you want to quickly see where a specific variable gets updated.

I'll try to implement it with SpanIndicators but it would be nice to have it as a built-in feature.

Comments (9)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Thanks for the suggestion.

Actipro Software Support
Posted 8 years ago by Jason Tobiasz
Was this suggestion ever implemented? I am also interested in a built-in feature like this...

If it was, what should I look for in the help file to get me rolling along? Thanks in advance.

[Modified at 07/16/2010 12:25 PM]
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Hi, sorry but it has not been added as a built-in feature at this time.

You could make use of the span indicator feature to custom implement it though, perhaps in response to selection change events.

[Modified at 07/16/2010 02:26 PM]

Actipro Software Support
Posted 8 years ago by Jason Tobiasz
Here's what I ended up doing...feel free to code review this in the case I'm doing something stupidly. Thanks in advance.

      private void FFSyntaxEditor_SelectionChanged(object sender, SelectionEventArgs e)
         const string selectedText = "__SelectedText__";

         if (Document.SpanIndicatorLayers.Contains(selectedText))
            int index = Document.SpanIndicatorLayers.IndexOf(selectedText);

         FindReplaceOptions find = new FindReplaceOptions();
         find.FindText = SelectedView.SelectedText;
         find.MatchCase = find.MatchWholeWord = true;

         if (find.FindText != String.Empty)
            SpanIndicatorLayer spanIndicatorLayer = new SpanIndicatorLayer(selectedText, 0);

            ActiproSoftware.SyntaxEditor.HighlightingStyle highlightingStyle = new ActiproSoftware.SyntaxEditor.HighlightingStyle(selectedText, selectedText, SystemColors.HighlightText, ControlPaint.LightLight(SystemColors.Highlight));

            FindReplaceResultSet result;
            int offset = 0;

            while ((result = Document.FindReplace.Find(find, offset)).Count > 0 && !result.PastDocumentEnd)
               spanIndicatorLayer.Add(new HighlightingStyleSpanIndicator(selectedText, highlightingStyle), result[0].StartOffset, result[0].Length);
               offset = result[0].EndOffset;

[Modified at 08/18/2010 10:52 AM]

[Modified at 08/18/2010 11:18 AM]
Posted 8 years ago by Jason Tobiasz
See this thread:

[Modified at 08/18/2010 10:59 AM]

[Modified at 08/18/2010 11:18 AM]
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Jason,

Several things... you may not want to add and remove the span indicator layer with each selecton change. Maybe keep it in there all the time.

Second, maybe only update the highlights if the selection actually moves to a new word.

Also be aware that your code will scan the entire doc with each selection change, which could obviously affect performance if you have anything but a small document.

Actipro Software Support
Posted 3 years ago by Heribert Scharnagl

Is this feature now implemented by default or is there any way to solve it?

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Heribert,

We don't have this feature implemented in the WinForms version.  In our newer WPF version, we have a sample that shows an easy way do to word highlighting, but that API has tagging features not found in the WinForms API that make that sort of thing easier to accomplish.  We hope to eventually backport our WPF API to the WinForms version so we can get all the features in sync across platforms.

Actipro Software Support
Posted 2 years ago by Mike Dempsey - Sr. Developer, Teradata Corp

I have had requests for this feature from my customers also.

It would be great if you could back port it to WinForms.

Information The latest build of this product (2018.1 build 0340) was released 4 months ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.