microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.18k stars 29.29k forks source link

Sticky scroll messes up accurate markdown scroll sync #166741

Open mjbvz opened 1 year ago

mjbvz commented 1 year ago
  1. With stick scroll enabled
  2. Open the md file:
    # h1
    # h2
    # h3
    # h4
    # h5
    # h6
    # h7
  3. Open markdown preview to side
  4. Scroll the preview slowly down to the bottom of the content

Bug Notice how the editor only scroll when you reach h7

I believe this is happening because of this logic for sticky scrolling : https://github.com/microsoft/vscode/blob/39911aac41bc0fc65118ec91ecc918cc053be3de/src/vs/editor/browser/viewParts/lines/viewLines.ts#L683

mjbvz commented 1 year ago

I'm fine with reveal taking sticky scroll into account. The issue for markdown though is that this causes the viewports to get out of sync

When you scroll all the way down in the preview, the editor is still showing line 2 at the top of the editor. If you then switch over to the editor and scroll it, the preview instantly jumps back to show line 2 in the preview

@alexdima Do I need to use editor.stickyScroll.maxLineCount to determine which range to reveal in the preview? Here's what I do today using the visible ranges event:

https://github.com/microsoft/vscode/blob/f8c9ae79ea9406439176b4c601fc4014e375189c/extensions/markdown-language-features/src/preview/topmostLineMonitor.ts#L32

alexdima commented 1 year ago

I think you're doing everything correct on your side, the problem here is that we went with the "cheap" implementation of sticky scrolling via an editor contribution. So the editor core doesn't really know that there is this thing at the top which hides certain lines by being rendered on top of them. That's why the visible ranges it emits also contain occluded lines. I'm sorry that I can't think of a straight-forward fix.