ScrollToEnd() is inefficient
AvalonEdit ScrollToEnd() is inefficient -- it sets ScrollOffset to infinity, and relies on the bounds check in arrange() to restore a sane ScrollOffset. Unfortunately, this has the effect of destroying all cached visual lines. This makes ScrollToEnd() inefficient in log-viewer style applications that frequently append to the document and call ScrollToEnd().
@dgrunwald is there a workaround for log-viewer style applications?
Using ScrollToVerticalOffset was considerably more efficient for me. I had added a method to an inherited class that looked like this:
/// <summary>
/// Similar functionality to ScrollToEnd but considerably more efficient.
/// </summary>
public void ScrollToLastLine()
{
this.ScrollToVerticalOffset(this.TextArea.TextView.GetVisualTopByDocumentLine(this.LineCount));
}
This works mostly well with one exception. When the last wraps (or even possibly any line, need to test) it goes to the visual top of the last line.. but the wrapped portion is still out of view (when I also need that in view). I've tried to account for that by obtaining the line height and adding that to the vertical offset but have been unsuccessful thus far on that front. I wanted to share this regardless in case it helps anyone out.
This appears to work with wrapping:
See if this words. I had it in an inherited class but you get the idea. It seems to perform as well as ScrollToVerticalOffset and also takes it all the way to the bottom (including wraps). I haven't tested it extensively but I'm going to.
/// <summary>
/// Similar functionality to ScrollToEnd but considerably more efficient.
/// </summary>
public void ScrollToLastLine()
{
this.ScrollTo(this.LineCount, 0);
}