Higlight text without replacing the existing language

SyntaxEditor for Windows Forms Forum

Posted 5 years ago by Mauricio Dominguez
Version: 12.1.0300



I have a syntaxeEditor that loads a set of language rules from an XML file

syntaxEditor.Document.LoadLanguageFromXml("ActiproSoftware.JScript.xml", 0);

How can I let the user to highlight all ocurrences of any word within the document without replacing the loaded language?



Comments (2)

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

Hi Mauricio,

You could use span indicators to accomplish that sort of thing, but you would need to create each instance of the indicator.  It would not be an automated process as it is with the lexical parser (via the XML).

Alternatively you could set the language's IsUpdating property to true, then add the word pattern to the loaded lexical parser, then set IsUpdating = false.  That will update the existing loaded lexer, and in that way, you don't have to use span indicators.

Actipro Software Support

Posted 5 years ago by Mauricio Dominguez

It worked, I want the document to highlight all ocurrences of a given string while keeping the style for the rest of the words.


The code I'm using is as follows:


            var language = syntaxEditor.Document.Language;
            language.IsUpdating = true;
            var style = new HighlightingStyle("H2", null, Color.Black, Color.LightBlue, DefaultableBoolean.Default, DefaultableBoolean.Default, HighlightingStyleLineStyle.Default);
            var lexicalPatternGroup = new LexicalPatternGroup(LexicalPatternType.Explicit, "T2", style, textToSearch);

            if (isMatchCase)
                lexicalPatternGroup.CaseSensitivity = CaseSensitivity.Sensitive;

            ((DynamicLexicalState)language.DefaultLexicalState).LexicalPatternGroups.Insert(0, lexicalPatternGroup);
            language.IsUpdating = false; 

[Modified 5 years ago]

The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.