Skip to content
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

Preserve Webview Scroll Position #26426

Merged
merged 6 commits into from
May 17, 2017
Merged

Conversation

mjbvz
Copy link
Collaborator

@mjbvz mjbvz commented May 11, 2017

Fixes #22995

Bug
If you switch away from an editor that users a webview, the scroll position is currently not preserved. This effects our release notes and the markdown preview. The root cause is that the webview is disposed of when the view is hidden.

Fix
Add some presisted state to track scrollProgress through the webview. Use this state in the standard html editor and in the release notes.

TODO

  • Make sure html preview handles case where content changes. I believe this should reset the scroll position
  • Handle dragging editor tab to create duplicate view. This should also copy over the scroll position

@mention-bot
Copy link

@mjbvz, thanks for your PR! By analyzing the history of the files in this pull request, we identified @jrieken and @joaomoreno to be potential reviewers.

@mjbvz mjbvz self-assigned this May 11, 2017
@mjbvz mjbvz force-pushed the preserve-webview-scroll branch 2 times, most recently from 35329bf to cc5f3bf Compare May 11, 2017 04:55
@mjbvz mjbvz requested a review from chrmarti May 11, 2017 04:56
@mjbvz mjbvz force-pushed the preserve-webview-scroll branch from cc5f3bf to 1e937f2 Compare May 11, 2017 04:58
@joaomoreno
Copy link
Member

Fixes #13256

@chrmarti
Copy link
Collaborator

@mjbvz The editor input can be used for multiple editors (e.g., through Split Editor). You probably want to store the scroll position separately from the input. See WalkThroughPart.load/saveTextEditorViewState() for a similar approach to what the BaseTextEditor and its subclasses do.

@mjbvz
Copy link
Collaborator Author

mjbvz commented May 11, 2017

Thanks for taking a look @chrmarti. I think I was actually closer to that behavior with my first draft of the implementation (which used private member on HtmlEditor) but since I wasn't using mementos I ran into problems when splitting views. Moving the state to the input fixed this but as you noted, this also introduce some other weird behavior when multiple previews are active.

Let me try the memento based approach and see how that works

@chrmarti
Copy link
Collaborator

What makes it harder than expected is that editors and inputs are both reused. Editors are reused for inputs of the same type in the same editor column IIRC. Switching between editor tabs in the same column can trigger setInput() calls on a single editor with different inputs. So one editor can cover multiple editor tabs.

@mjbvz
Copy link
Collaborator Author

mjbvz commented May 12, 2017

@chrmarti Thanks for the help. I prototyped the approach using mementos but I don't think it is correct here either, at least for the normal html preview. The scroll position should always be associated with the content, not just with the resource url. At present, we also do not want to restore the previous scroll position in an html preview after you restart VS Code

The approach that saved view state on the Input felt more correct to me when I was actually using it. The problem with it seems to be that the same input can be shared between editors in multiple panes however. Can we sit down together next week to discuss this more?

@mjbvz mjbvz force-pushed the preserve-webview-scroll branch from dd42176 to 1e937f2 Compare May 12, 2017 04:21
mjbvz added 5 commits May 17, 2017 14:04
Fixes microsoft#22995

**Bug**
If you switch away from an editor that users a webview, the scroll position is currently not preserved. This effects our release notes and the markdown preview. The root cause is that the webview is disposed of when the view is hidden.

**Fix**
Add some presisted state to track scrollProgress through the webview. Use this state in the standard html editor and in the release notes.
Fixes microsoft#22995

**Bug**
If you switch away from an editor that users a webview, the scroll position is currently not preserved. This effects our release notes and the markdown preview. The root cause is that the webview is disposed of when the view is hidden.

**Fix**
Add some presisted state to track scrollProgress through the webview. Use this state in the standard html editor and in the release notes.
@mjbvz mjbvz force-pushed the preserve-webview-scroll branch from 1e937f2 to ac1d20b Compare May 17, 2017 21:10
@mjbvz mjbvz force-pushed the preserve-webview-scroll branch from 8032c00 to 4309165 Compare May 17, 2017 21:13
@mjbvz
Copy link
Collaborator Author

mjbvz commented May 17, 2017

Ok, merging the initial memento based implementation as we discussed

@mjbvz mjbvz merged commit dea44c8 into microsoft:master May 17, 2017
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Markdown Preview does not preserve scroll position
5 participants