Higlight text without replacing the existing language

SyntaxEditor for Windows Forms Forum

Posted 10 years ago by Mauricio Dominguez
Version: 12.1.0300
Avatar

Hello,

 

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?

 

Thanx

Comments (2)

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

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 10 years ago by Mauricio Dominguez
Avatar

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);
            
            if(!language.HighlightingStyles.Contains(style))
                language.HighlightingStyles.Add(style);
            
            language.IsUpdating = false; 

[Modified 10 years ago]

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

Add Comment

Please log in to a validated account to post comments.