How to programatically change selected text properties?

SyntaxEditor for WPF Forum

Posted 8 years ago by IneedHelp
Version: 16.1.0633
Avatar

Hello. Assuming I have selected some text using the search function:

EditorSearchOptions options = new EditorSearchOptions();
options.FindText = "test";
options.PatternProvider = SearchPatternProviders.Normal;
ISearchResultSet resultSet = _syntaxEditor.ActiveView.Searcher.FindNext(options);

How would I be able to change the highlighted text properties (font family, font size, text color) dynamically in code?

Is there a similar procedure to what we'd do with selected strings in a rich text editor?

Comments (4)

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

Hello,

I assume you are referring to the Search Result Highlighting feature?  If so, I believe you'd want to update the IHighlightingStyle in the AmbientHighlightingStyleRegistry that corresponds to the IClassificationType returned by:

new DisplayItemClassificationTypeProvider().FindMatchHighlight


Actipro Software Support

Posted 8 years ago by IneedHelp
Avatar

Thank you for the answering.

Basically what I want to do is to be able to modify some ranges of text, ideally the ones returned by the search function.

Would it be possible to provide a small example code snippet?
I am not entirely sure how to achieve this by reading the documentation.



To be more specific, let's assume that the syntax editor contains the following text:
"The brown fox jumps the fence."

How could I change the text properties (font family, font color, font size) of the word "brown" only?

[Modified 8 years ago]

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

Hello,

Something like this would work:

var style = AmbientHighlightingStyleRegistry.Instance[new DisplayItemClassificationTypeProvider().FindMatchHighlight];
style.FontSize = 20;

var options = new EditorSearchOptions();
options.FindText = "class";
control.editor.ActiveView.HighlightedResultSearchOptions = options;

Classification taggers can be used to highlight various ranges too, such as in the AdornmentsHighlightWord QuickStart.  But if you want to just highlight search results, the above is easiest.


Actipro Software Support

Posted 8 years ago by IneedHelp
Avatar

Thank you, this has been very helpful.

The latest build of this product (v24.1.1) 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.