microsoft / vscode

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

Markdown preview does not scroll to top on new URI #164071

Open dsanders11 opened 2 years ago

dsanders11 commented 2 years ago

Does this issue occur when all extensions are disabled?: N/A (depends on the built-in markdown extension)

Steps to Reproduce:

  1. Create two Markdown documents, one with a relative link to the other, and enough content in both documents to scroll down
  2. Preview the document with the link and scroll down to the link, then click it

Expected Behavior:

The link to the other document should open the new document at the top

Actual Behavior:

The scroll position stays the same, opening the new document at a random spot in that document

Other Information:

This change is probably straightforward to make, but it would break the existing behavior. I'm struggling to imagine why that behavior would be desirable though, so not sure it would actually affect anyone in a meaningful way.

cc @mjbvz

vscodenpa commented 2 years ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.72.2. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

K0more commented 2 years ago

Hey can I get this assigned

dsanders11 commented 2 years ago

@K0more, no need to have the issue assigned to you. You're welcome to make a PR to fix it if you want. 🙂

LoopThrough-i-j commented 2 years ago

@dsanders11 I tried digging into the issue and found that because it is an in-place reload of the Preview, the scroll bar tries to get back to its original position after rerendering. Do you recommend opening a new tab for the linked document's preview, that would ideally solve the issue.

P.S. I tried setting the StartScrollLine number of the linked document to 0 before rerendering but it didn't seem to work.

cc. @mjbvz

GauravB159 commented 2 years ago

Hello, I'm new to Open Source development and I was going through the Good First Issue label and figured I could take a crack at this one.

I think I have traced the problem back to this section of code, but I'm not sure how to proceed.

image

This is in the file "extensions\markdown-language-features\preview-src\index.ts"

It seems the scrollProgress of a preview window is stored in a state variable and when the link is clicked, the scrollProgress is restored using that piece of code. I'm not sure if that is intended behavior, or a bug fix for another issue.

Commenting out line 65 actually solves the issue, but again, I am not sure if the line was added for some other bug fix or intended behavior, since the commit message for that line does not specify a bug fix.

cc: @dsanders11

Djunnni commented 2 years ago

@dsanders11 hi, i have a question about Testing "/src/vs/workbench/contrib/webview/browser/pre/index.html"

i want to fix some of code there. but when i fixed then run complie-web, it's not changed!

how can test this point ?

i run

1. yarn
2. code change ...
3. npm run compile-web
4. npm run gulp
5. ./script/code-web.sh
mjbvz commented 1 year ago

Reopening since the PR that fixed this had to be reverted: #168224

joyceerhl commented 1 year ago

This still repros for me :(

mjbvz commented 1 year ago

Actually I probably need to fix this for this iteration as the code now appears to be setting the webview state incorrectly

rzhao271 commented 1 year ago

The preview did not scroll to the top: Screencap, showing that when opening the second file, the preview is still stuck at the bottom

mjbvz commented 1 year ago

@rzhao271 Which commit did you test on? This fix just went in and is only in deedbd33f5dc57795e11da7c2a26b5a05a93485b

rzhao271 commented 1 year ago

I am on deedbd33f5dc57795e11da7c2a26b5a05a93485b

N-NeelPatel commented 1 year ago

@mjbvz - is this fixed now?