This is a migrated thread and some comments may be shown as answers.

Highlight all instance of selection in a document

5 Answers 87 Views
SyntaxEditor
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 05 Mar 2021, 01:52 PM

Hello,

Notepad++ (and other editors) have a feature where you can select a term and all instance/occurrences of this term in the document are highlighted as well.

Is this also possible in the SyntaxEditor and can this be implemented in a similar fassion. I am using the Visual basic and the CSharp syntax highlighting.

There is a functionality called HighlightAllMatches but I don't really know if this is the right method or how to Trigger it correctly.

Thanks for your time.

5 Answers, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 10 Mar 2021, 10:39 AM

Hello Ben,

Indeed, it is possible to highlight a certain word by using either the TextSearchUnderlineTagger or TextSearchHighlightTagger and utilizing their UpdateSearchWord method. A good example of how this can be implemented can be observed in the Taggers demo from our WPF Controls Samples demo application.

Can you please have a look and let me know if any of these two taggers will work for you? I will be awaiting your reply.

Regards,
Dilyan Traykov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Ben
Top achievements
Rank 1
answered on 11 Mar 2021, 07:17 AM

Hallo Dilyan,

this seems to be exactly what I am looking for. I will go on vacation soon so I will test it later.

Thank you,

Ben

0
Dilyan Traykov
Telerik team
answered on 11 Mar 2021, 11:38 AM

Hello Ben,

Do let me know once you manage to test this out. I will be awaiting your reply.

Have a nice vacation!

Regards,
Dilyan Traykov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Ben
Top achievements
Rank 1
answered on 29 Mar 2021, 05:25 AM

Hello,

It works like a charm:

this.selectionWordTagger =   this.syntaxEditor.TaggersRegistry.GetTaggers<TextHighlightTag().OfType<TextSearchHighlightTagger>().First();
 
this.syntaxEditor.Selection.SelectionChanged += this.OnSelectionChanged;

 

private void OnSelectionChanged(object sender, EventArgs e)
{
    if (!this.syntaxEditor.Selection.IsEmpty)
    {
        string searchedWord = this.syntaxEditor.Selection.GetSelectedText();
        if (!string.IsNullOrWhiteSpace(searchedWord))
        {
            this.selectionWordTagger.UpdateSearchWord(searchedWord);
        }
    }
    else
    {
        this.selectionWordTagger.UpdateSearchWord(string.Empty);
    }
}

 

This is all you need from the example.

0
Dilyan Traykov
Telerik team
answered on 29 Mar 2021, 04:32 PM

Hello Ben,

I'm glad to hear that you've managed to achieve the desired result and would like to thank you for sharing your approach with our community.

Regards,
Dilyan Traykov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
SyntaxEditor
Asked by
Ben
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Ben
Top achievements
Rank 1
Share this question
or