AvalonEdit icon indicating copy to clipboard operation
AvalonEdit copied to clipboard

ScrollToEnd() is inefficient

Open dgrunwald opened this issue 11 years ago • 3 comments

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 avatar Aug 09 '14 15:08 dgrunwald

@dgrunwald is there a workaround for log-viewer style applications?

goswinr avatar Jun 02 '17 09:06 goswinr

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.

blakepell avatar Mar 02 '20 21:03 blakepell

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);
}

blakepell avatar Apr 28 '20 21:04 blakepell