locked
VS2010: Slow scrolling? RRS feed

  • Question

  • I'm using the editor to scroll enough so that the line I want is at the top of the editor, to accomplish this i'm using

        private void performScroll(IHsEntries tag)
        {
          IViewScroller scroller = this._textView.ViewScroller;
          int start = tag.location.x1 + this._textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(tag.location.y1).Start.Position;
          int length = tag.location.x2 - tag.location.x1;
          SnapshotSpan span = new SnapshotSpan(this._textView.TextBuffer.CurrentSnapshot, start, length);
          SnapshotSpan visibleSpan = this._textView.TextViewLines.FormattedSpan;
          int topline = this._textView.TextBuffer.CurrentSnapshot.GetLineFromPosition(visibleSpan.Start.Position).LineNumber;
          int needsScroll = tag.location.y1 - topline - 2;
          topline = needsScroll;
          needsScroll = Math.Max(Math.Abs(needsScroll), 0);
    
          scroller.ScrollViewportVerticallyByLines(topline > 0 ? ScrollDirection.Down : ScrollDirection.Up, needsScroll);
          //scroller.EnsureSpanVisible(span, EnsureSpanVisibleOptions.AlwaysCenter);
        }

    which works, but has a very high noticable lag when it has to scroll a large distance. If I swap the last two lines, (so having it do the same number of calculations) the scroll is almost instantanously. So I'm wondering why it can center a scroll very quickly but not say scroll xxx lines down.

    The larger the distance it has to scroll, the slower it is. I haven't had the time to upgrade to the RTM version yet so I'm still using the RC, but has anyone notice this same behaviour?

    Monday, June 7, 2010 10:51 PM

Answers

  • Hi Phyx - ScrollViewportVerticallyByLines will scroll one line at a time until all of the lines have been scrolled, which will cause layouts proportional to the number of lines.  EnsureSpanVisible does a single layout and is therefore significantly faster.  Make sense?

    Brittany Behrens | Program Manager | Visual Studio Platform - Editor | The Visual Studio Blog | @VSEditor on Twitter

    • Proposed as answer by Brittany Behrens Tuesday, June 15, 2010 1:17 AM
    • Marked as answer by Phyx Tuesday, June 15, 2010 7:09 AM
    Tuesday, June 15, 2010 1:17 AM

All replies

  • Hi Phyx - ScrollViewportVerticallyByLines will scroll one line at a time until all of the lines have been scrolled, which will cause layouts proportional to the number of lines.  EnsureSpanVisible does a single layout and is therefore significantly faster.  Make sense?

    Brittany Behrens | Program Manager | Visual Studio Platform - Editor | The Visual Studio Blog | @VSEditor on Twitter

    • Proposed as answer by Brittany Behrens Tuesday, June 15, 2010 1:17 AM
    • Marked as answer by Phyx Tuesday, June 15, 2010 7:09 AM
    Tuesday, June 15, 2010 1:17 AM
  • Hmm.. that's rather odd, I would have expected it to scroll the entire distance in one go. But ok, I can change how I calculate the visible span and then use one of the other methods which do scroll in one go.

    Thanks :)

    Tuesday, June 15, 2010 7:09 AM