-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added option to preserve the preview window to avoid refreshing when … #607
Conversation
It seems like a simple fix but I'm concerned about unexpected side effects. This extension is largely inspired by the Markdown extension which does not use this option: https://github.com/microsoft/vscode/blob/6a4e5cc26b29359472378c2a8951c33f4ea73244/extensions/markdown-language-features/src/preview/preview.ts#L643-L646 Since the Markdown is developed by the VS Code core team, I tend to believe that there's a good reason. Also, I don't think we should introduce an new option. |
https://code.visualstudio.com/api/references/vscode-api#WebviewPanelOptions says
I don't actually know what the overhead is — is it just that the web view is consuming its normal amount of memory even when not visible, or does enabling this option somehow use even more memory than normal? I added an option because if this is really detrimental, users may want the option of trading restoration speed for memory use. Saving and restoring scroll position is also an option but would still require a re-render on load, which is slower than just restoring. I've been using my fork of this extension and haven't noticed any problems — on the contrary I've really been enjoying the quick (nearly zero) loading speed when switching between tabs. Then again I am just one user. |
That's a good point. asciidoctor-vscode/preview-src/index.ts Lines 20 to 28 in 2075fab
Then, we can add an option (named "Instant Restore"?) to retain the WebView context when hidden that clearly states that this feature has a high memory overhead (quoting the documentation). What do you think? |
I think this makes sense. So all that would need to be added is the ability to restore the scroll position when |
That's correct! You will also need to add a description for this new option and update the README but it's just small details. |
…e background Added setting to enable/disable fast reloading at expense of memory usage Updated extension docs accordingly
@Mogztter I pushed my changes. The only thing I couldn't do was the French and Japanese translations of the setting. |
Awesome, thanks @rben01 ! |
…e background Added setting to enable/disable fast reloading at expense of memory usage Updated extension docs accordingly
f71b5b9
to
f54962e
Compare
I rebased on master and force-pushed (to fix the conflict) |
…g webview from background
…iidoctor-vscode into preserve-preview-pane
Actually I think that this behavior was always present in the extension; if I'm not mistaken it always required a scroll to re-sync the preview and the editor. In any case I think I've fixed that issue and have now implemented 100% scroll position restoration. The logic I've implemented tries to respect the most recent user action by saving the corresponding line position and restoring it when the web view is restored. Whichever is the most recent of: 1. scrolling the editor 2. changing the selection in the editor 3. scrolling the preview — will be used to restore the preview's scroll position when it comes back from the background. This happens regardless of whether the new |
It's working nicely now, thanks! The only case when it does not restore the scroll position is when:
Anyway, that's a small detail and it's already a huge improvement so I'm willing to merge. Let me know if you want to fix this last case or not. |
Odd, I'm not seeing that behavior — if I try to reproduce your video I get the intended behavior. Screen.Recording.2022-07-27.at.11.08.49.AM.mp4All I can think is that maybe you changed a preview setting without closing and reopening the window? (I think for the the most part the settings are only loaded when the window is created, and are never refreshed.) Anyway, please do merge! I'll see if there's something else that might be causing this discrepancy. |
You need to scroll further down when the preview is hidden. In your video you scrolled back to the top. |
Hmm, scrolling down also works for me. |
Anyway, that's not a big deal. Thanks again for your contribution 🤗 |
…switching away, and added setting to control this behavior.
(Simple fix;
vscode.window.createWebviewPanel
takes a parameter for this very thing.)If accepted, it would close #603