Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I highlight syntax errors using ICSharpCode.TextEditor.TextEditorControl?

I'm using ICSharpCode.TextEditor.TextEditorControl as my DSL editor. When I get DSL compilation errors, I would like to highlight the offending text to provide a better user experience. However, I'm having difficulty finding how to do this.

So far, I've found that there is a ShowInvalidLines property but I don't see a way to mark any lines as invalid. I also see HighlightSpanStack property of LineSegment and HighlightingStrategy but not sure how they are supposed to be used.

Any help would be appreciated. Thanks!

like image 762
Igor Pashchuk Avatar asked Sep 15 '11 21:09

Igor Pashchuk


1 Answers

To highlight a piece of text use a TextMarker. The following code underlines 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 highlight the text with any background and foreground colour and the TextMarkerType supports underlining, wavy lines or a solid block of colour.

like image 110
Matt Ward Avatar answered Nov 03 '22 09:11

Matt Ward