Suggestion: highlight selected word

SyntaxEditor for Windows Forms Forum

Posted 15 years ago by Erel Uziel
Version: 4.0.0280
Avatar
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 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks for the suggestion.


Actipro Software Support

Posted 14 years ago by Jason Tobiasz
Avatar
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 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
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 14 years ago by Jason Tobiasz
Avatar
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);
            Document.SpanIndicatorLayers[index].Clear(selectedText);
            Document.SpanIndicatorLayers.Remove(Document.SpanIndicatorLayers[index]);
         }

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

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

            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 14 years ago by Jason Tobiasz
Avatar
See this thread:
http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=929#3166

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

[Modified at 08/18/2010 11:18 AM]
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
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 8 years ago by Heribert Scharnagl
Avatar

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

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

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 8 years ago by Michael Dempsey - Sr. Developer, Teradata Corp
Avatar

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

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

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.