How to highlight syntax errors using ICSharpCode.TextEditor.TextEditorControl?

I am using ICSharpCode.TextEditor.TextEditorControl as my DSL editor. When I get DSL compilation errors, I would like to emphasize the offensive text to provide a better user interface. However, it’s hard for me to find how to do this.

So far, I have found that the ShowInvalidLines property ShowInvalidLines , but I see no way to mark any rows as invalid. I also see the HighlightSpanStack LineSegment and HighlightingStrategy property, but I'm not sure how they should be used.

Any help would be greatly appreciated. Thanks!

+6
source share
1 answer

To select a piece of text, use TextMarker. The following code emphasizes the word "Error" with a red wavy line.

 TextEditorControl textEditor = new TextEditorControl(); textEditor.Text = "Mark Error"; int offset = 5; int length = 5; TextMarker marker = new TextMarker(offset, length, TextMarkerType.WaveLine, Color.Red); textEditor.Document.MarkerStrategy.AddMarker(marker); 

You can select text with any background and foreground color, and TextMarkerType supports underline, wavy lines, or a solid block of color.

+11
source

Source: https://habr.com/ru/post/897426/


All Articles