Search Result Highlighting
When performing searches, many modern editors actively display matching results as the user types the find text. SyntaxEditor supports the live highlighting of search results.
There are two common usage scenarios for search result highlighting: incremental searches and search panes.
Incremental Search Highlights
The Incremental Search features built into SyntaxEditor allow for an end user to quickly search for a string that they type. When the SyntaxEditor.IsSearchResultHighlightingEnabled property is set to true
(the default), highlights will appear throughout the document showing all matches for the find text.
This allows the end user to immediately visualize where all matches occur instead of having to navigate through the incremental search matches one-by-one.
Search Pane Highlights
If your app has a search pane, it may wish to highlight search results live as the user types in the search pane's Find textbox, and prior to the user pressing the Find button.
If you are using the built-in search overlay pane, this will happen automatically.
This can be achieved by setting an ISearchOptions instance to the IEditorView.HighlightedResultSearchOptions property. Every time that property is set or an option is updated, a worker task kicks off that does a find all operation in the document and then when complete, updates the search result highlights.
Set the property to a null
value when the search pane closes, so that all highlights will be removed.
This code shows how highlights could be displayed over any text in the document with the words "highlight this text":
EditorSearchOptions options = new EditorSearchOptions;
options.FindText = "highlight this text";
editor.ActiveView.HighlightedResultSearchOptions = options;
Important
Make sure that the ISearchOptions object passed in implements an Equals
method override that examines each property in the options, since this is used for internal comparisons. The predefined EditorSearchOptions class does so.
Requirements
This code is required to be called once per application instance since it registers the classification types and related styles for the highlights.
new DisplayItemClassificationTypeProvider().RegisterAll();
Important
If the classification types are not registered, then the highlights might not display.