Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avalonedit How to invalidate Line Transformers

I've added a LineTransformerClass that is derived from DocumentColorizingTransformer to the TextEditor:

TxtEditCodeViewer.TextArea.TextView.LineTransformers.Add(new ColorizeAvalonEdit());

Is there any programmatic way of invoking invalidation on the Linetransformer?

I've readily assumed that since it is added to the textview, the following should work:

TxtEditCodeViewer.TextArea.TextView.InvalidateVisual();
TxtEditCodeViewer.TextArea.TextView.InvalidateArrange();
TxtEditCodeViewer.TextArea.TextView.InvalidateMeasure();

But they don't. Just in case, I've tried the following as well:

//TxtEditCodeViewer.TextArea.TextView.InvalidateVisual();
//TxtEditCodeViewer.TextArea.TextView.InvalidateArrange();
//TxtEditCodeViewer.TextArea.TextView.InvalidateMeasure();
//TxtEditCodeViewer.InvalidateVisual();
//TxtEditCodeViewer.InvalidateArrange();
//TxtEditCodeViewer.InvalidateMeasure();
//TxtEditCodeViewer.TextArea.InvalidateArrange();
//TxtEditCodeViewer.TextArea.InvalidateMeasure();
//TxtEditCodeViewer.TextArea.InvalidateVisual();
like image 675
l46kok Avatar asked Aug 20 '12 06:08

l46kok


1 Answers

The text view maintains a cache of the generated visual lines. Forcing WPF to repaint the control just makes it re-use the results in the cache and does not call your line transformer again.

You can use the TextView.Redraw method to invalidate the cached visual lines:

textEditor.TextArea.TextView.Redraw(segment); // invalidate portion of document
textEditor.TextArea.TextView.Redraw(); // invalidate whole document

This works for both ElementGenerators and LineTransformers.

For BackgroundRenderers, it is not necessary to invalidate visual lines. Instead, just tell the text view to invalidate the layer to which your background renderer belongs:

textEditor.TextArea.TextView.InvalidateLayer(this.Layer);
like image 83
Daniel Avatar answered Sep 28 '22 09:09

Daniel