Skip to content

Preserve Webview Scroll Position - #26426

Merged
Matt Bierner (mjbvz) merged 6 commits into
microsoft:masterfrom
mjbvz:preserve-webview-scroll
May 17, 2017
Merged

Matt Bierner (mjbvz) merged 6 commits into
microsoft:masterfrom
mjbvz:preserve-webview-scroll

Conversation

@mjbvz

@mjbvz Matt Bierner (mjbvz) commented May 11, 2017 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown

Matt Bierner (@mjbvz), thanks for your PR! By analyzing the history of the files in this pull request, we identified Johannes Rieken (@jrieken) and João Moreno (@joaomoreno) to be potential reviewers.

@joaomoreno

Copy link
Copy Markdown
Contributor

Fixes #13256

@chrmarti

Copy link
Copy Markdown
Collaborator

Matt Bierner (@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
Copy Markdown
Contributor Author

Thanks for taking a look Christof Marti (@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
Copy Markdown
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
Copy Markdown
Contributor Author

Christof Marti (@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?

Matt Bierner 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

Copy link
Copy Markdown
Contributor Author

Ok, merging the initial memento based implementation as we discussed

@mjbvz
Matt Bierner (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