ScrollToEnd() is inefficient #15

Open
opened 2014-08-09 10:28:24 -05:00 by dgrunwald · 3 comments
dgrunwald commented 2014-08-09 10:28:24 -05:00 (Migrated from github.com)

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().

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().
goswinr commented 2017-06-02 04:55:01 -05:00 (Migrated from github.com)

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

@dgrunwald is there a workaround for log-viewer style applications?
blakepell commented 2020-03-02 15:24:30 -06:00 (Migrated from github.com)

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.

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 commented 2020-04-28 16:07:13 -05:00 (Migrated from github.com)

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);
}
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); } ```
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-icsharpcode/AvalonEdit#15
No description provided.