You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support to scroll markdown preview with source scrolling #5047
feature-requestRequest for new features or functionalitymarkdown-extThe Markdown extension: language features and previewplan-itemVS Code - planned item for upcoming
Open a markdown preview to the side of markdown source
Scroll source file
It would be nice to have a way to lock the preview and scroll at the same time. Especially nice for longer markdown files.
This came in from an internal MS writer using VS Code for Markdown.
Reacted by Peter Jaszkowiak, Joshua Sleeper, msenturk, Sébastien Allamand, Mike Murkovic, Fabian Lauer, Răzvan T Duca, gyzhao, Javier Candalaft, Julian Gilyadov and 28 more
there is another duplicate issue #6992 and I've put my knowledge there. markdown-it (our current markdown engine) does support generating scroll map for Editor's to implement sync-preview. The only thing left here is adding handlers inside TextEditor.
I am not familiar with the code, but is the implementation of this any different than the Git integration where the diffs are shown side by side and the scrolling is synchronized?
I've been considering a few ways to implement this feature, and want to toss out three possible ideas to see if anyone on the VSCode team or externally has any thoughts on which direction to go in.
(Sorry for the long writeup)
Scroll Events
My initial thought was to create a new API for monitoring when a text editor is scrolled. or more generally has its viewport changed. The viewport would likely be expressed in terms of line numbers instead of pixels, and the markdown extension would subscribe to these events for markdown source documents to implement scrolling synchronization.
Scrolling events are much closer to underlying the dom than anything that our current APIs expose.
Each extension/file type would have to implement its own scrolling synchronization logic.
Performance concerns. This could generate a lot of events.
Would require another API to sync scrolling from the preview to the editor.
Internal Editor Scrolling Associations
While discussing the purposed scroll event API with Kai Maetzel (@kieferrm) , its many drawbacks became clear. Since exposing scroll events felt too low level, we talked about how we may be able to create a more declarative API that hides most of the scrolling synchronization implementation details.
In this model, the workbench would keep track of the text editor associated with a markdown preview view. When the source text editor is scrolled, the workbench would map the source's location to a target position in the preview. The scroll mapping would be computed using html attributes on the preview's generated html:
Could add new features more easily, such as bi-direction scrolling synchronization.
Disadvantages
More difficult to implement.
Performance concerns. We should only generate scrolling events when someone cares about them.
More limited applications for extension authors.
Entirely implicit API that is not easy to debug or customize.
Preview View
I liked this second approach much better, but while talking with Peng Lyu (@rebornix) about this, he presented another idea that may be easier to implement and also offers some useful functionality for the rest of VSCode: a preview view.
The preview view would visually look somewhat like the current diff view, with a split pane layout. One side would have a text editor, while the other side would have have a rendered preview of the editor's content. The scrolling synchronization implementation would be similar to that described before.
The main advantage of the preview view is that it could be used to implement consistent preview experiences for multiple extensions and file types. I imagine the api would be similar to current TextDocumentContentProvider api:
Same advantages as "Internal Editor Scrolling Associations" for scrolling synchronization.
Direct association between editor and preview view allows us to avoid some potential design and perf issues.
Makes previews a more well defined concept in VSCode.
Disadvantages
Same disadvantages as "Internal Editor Scrolling Associations"
More generic, so it would require some new APIs.
In this model, the preview would no longer be a separate view that can be detached from the editor and moved about on its own. The editor and preview would always be bound to each other.
I think that we can probably rule out exposing scroll events directly. That leaves either the "Internal Editor Scrolling Associations", which uses our current model to synchronize scrolling between the preview and the editor, or the preview view, which introduces a new concept to do the same while also bringing potentially new extensibility to VSCode. I know that there's been some noise around better supporting previews recently.
Please let me know if you have any thoughts on either approach, or if you have another idea that is worth considering.
This won't help deciding on the approach but... I can see this being quite useful for other use cases; what if I were to open a TypeScript file and wanted to see the matching JavaScript next to it in some sort of "TypeScript preview"? It would be cool to have them linked too. Or anything else which produces sourcemaps. 👍
Many people have already asked us to expose the current state of the view port. Unless we decide to tell them that won't ever happen we should seriously consider that. Also, with some debouncing tricks we should be able to avoid performance issues.
Re Internal Editor Scrolling Associations:
That sounds like a lot of magic to me
Re Preview View:
The idea has appeal but will add lots of new API. It's not enough to associate a string to a scheme using a provider indirection. Because for markdown-cases that string should be rendered as html but for cases like the one Joao pointed out, JS from TS should be shown using an editor. That means we need to be able to say what UI piece is supposed to be created, like create PreviewView and create Editor which requires more API
I really would like having markdown source and preview in ONE editor at least when I am authoring the markdown. If I am reading markdown, I would not expect the source of the file to be visible. It seems to me that we then have 2 modes how to read markdown, or we need a way to allow the preview to span the full size of the editor if the user does not care about the sources.
For now, going with the scroll events API approach seems like a good first step though.
Just merged in #18762 which prototypes similar functionality and will be in tomorrow's insiders build. We still can't do scroll sync yet since we have no api for getting the vscode editor viewport, but the change adds the following:
When opening the markdown preview, automatically scroll to view the current selected line from the markdown editor.
When changing the selection in the markdown editor, scrolls the markdown preview to reveal the corresponding element.
When double clicking an element on the markdown preview page, opens an editor and reveals this line in the center.
Indicator in preview shows the currently selected line in the markdown editor
This can be disabled using markdown.preview.experimentalSyncronizationEnabled
We would really appreciate any feedback on the behavior of these features and other additions that may be helpful. Again, proper synchronization based on scrolling of the text editor is still something we are investigating, but these new features should be helpful when working with markdown documents.
Reacted by Steven, Yukai Huang, Max Wu, Jon Douglas, Philipp Kief and pidan
I've opened #19459 to track scroll sync from the editor to the markdown preview. The reverse works, but for editor to preview we currently only track the selection in the editor, not the viewport itself.
feature-requestRequest for new features or functionalitymarkdown-extThe Markdown extension: language features and previewplan-itemVS Code - planned item for upcoming
Activity
[-]Support locking Markdown preview to source file[/-][+]Support to scroll markdown preview with source[/+][-]Support to scroll markdown preview with source[/-][+]Support to scroll markdown preview with source scrolling[/+]tedhudek commentedon Jun 23, 2016
hi Kai Maetzel (@kieferrm), just curious if you have an ETA for this feature. Greg Van Liew (@gregvanl) and I were discussing it. Thanks!
rebornix commentedon Jun 24, 2016
there is another duplicate issue #6992 and I've put my knowledge there.
markdown-it(our current markdown engine) does support generating scroll map for Editor's to implement sync-preview. The only thing left here is adding handlers inside TextEditor.akillcool commentedon Aug 14, 2016
It's really an user-friendly feature.
helphi commentedon Aug 27, 2016
+1
nadoo commentedon Sep 23, 2016
It's a necessary feature to throw my current markdown editor away.
1 remaining item
samherrmann commentedon Nov 2, 2016
I am not familiar with the code, but is the implementation of this any different than the Git integration where the diffs are shown side by side and the scrolling is synchronized?
mjbvz commentedon Jan 10, 2017
I've been considering a few ways to implement this feature, and want to toss out three possible ideas to see if anyone on the VSCode team or externally has any thoughts on which direction to go in.
(Sorry for the long writeup)
Scroll Events
My initial thought was to create a new API for monitoring when a text editor is scrolled. or more generally has its viewport changed. The viewport would likely be expressed in terms of line numbers instead of pixels, and the markdown extension would subscribe to these events for markdown source documents to implement scrolling synchronization.
The API here would look something like this:
Advantages
Disadvantages
Internal Editor Scrolling Associations
While discussing the purposed scroll event API with Kai Maetzel (@kieferrm) , its many drawbacks became clear. Since exposing scroll events felt too low level, we talked about how we may be able to create a more declarative API that hides most of the scrolling synchronization implementation details.
In this model, the workbench would keep track of the text editor associated with a markdown preview view. When the source text editor is scrolled, the workbench would map the source's location to a target position in the preview. The scroll mapping would be computed using html attributes on the preview's generated html:
Advantages
Disadvantages
Preview View
I liked this second approach much better, but while talking with Peng Lyu (@rebornix) about this, he presented another idea that may be easier to implement and also offers some useful functionality for the rest of VSCode: a preview view.
The preview view would visually look somewhat like the current diff view, with a split pane layout. One side would have a text editor, while the other side would have have a rendered preview of the editor's content. The scrolling synchronization implementation would be similar to that described before.
The main advantage of the preview view is that it could be used to implement consistent preview experiences for multiple extensions and file types. I imagine the api would be similar to current
TextDocumentContentProviderapi:Advantages
Disadvantages
I think that we can probably rule out exposing scroll events directly. That leaves either the "Internal Editor Scrolling Associations", which uses our current model to synchronize scrolling between the preview and the editor, or the preview view, which introduces a new concept to do the same while also bringing potentially new extensibility to VSCode. I know that there's been some noise around better supporting previews recently.
Please let me know if you have any thoughts on either approach, or if you have another idea that is worth considering.
Thanks
CC Martin Aeschlimann (@aeschli) Johannes Rieken (@jrieken) Benjamin Pasero (@bpasero) João Moreno (@joaomoreno) Erich Gamma (@egamma) Daniel Imms (@Tyriar)
joaomoreno commentedon Jan 10, 2017
This won't help deciding on the approach but... I can see this being quite useful for other use cases; what if I were to open a TypeScript file and wanted to see the matching JavaScript next to it in some sort of "TypeScript preview"? It would be cool to have them linked too. Or anything else which produces sourcemaps. 👍
jrieken commentedon Jan 10, 2017
Re Scroll Events:
Many people have already asked us to expose the current state of the view port. Unless we decide to tell them that won't ever happen we should seriously consider that. Also, with some debouncing tricks we should be able to avoid performance issues.
Re Internal Editor Scrolling Associations:
That sounds like a lot of magic to me
Re Preview View:
The idea has appeal but will add lots of new API. It's not enough to associate a
stringto aschemeusing a provider indirection. Because for markdown-cases that string should be rendered as html but for cases like the one Joao pointed out, JS from TS should be shown using an editor. That means we need to be able to say what UI piece is supposed to be created, like create PreviewView and create Editor which requires more APIbpasero commentedon Jan 10, 2017
I really would like having markdown source and preview in ONE editor at least when I am authoring the markdown. If I am reading markdown, I would not expect the source of the file to be visible. It seems to me that we then have 2 modes how to read markdown, or we need a way to allow the preview to span the full size of the editor if the user does not care about the sources.
For now, going with the scroll events API approach seems like a good first step though.
Arnavion commentedon Jan 10, 2017
The
Internal Editor Scrolling Associationsidea is similar to sourcemaps. It would probably map to other uses that have explicit sourcemaps.mjbvz commentedon Jan 19, 2017
Just merged in #18762 which prototypes similar functionality and will be in tomorrow's insiders build. We still can't do scroll sync yet since we have no api for getting the vscode editor viewport, but the change adds the following:
This can be disabled using
markdown.preview.experimentalSyncronizationEnabledWe would really appreciate any feedback on the behavior of these features and other additions that may be helpful. Again, proper synchronization based on scrolling of the text editor is still something we are investigating, but these new features should be helpful when working with markdown documents.
mjbvz commentedon Jan 23, 2017
Next 1.9 insiders also adds markdown preview to editor scroll synchronization:
Again, let us know if you have any feedback or run into any bugs.
joaomoreno commentedon Jan 26, 2017
Closing as this seems done.
mjbvz commentedon Jan 26, 2017
I've opened #19459 to track scroll sync from the editor to the markdown preview. The reverse works, but for editor to preview we currently only track the selection in the editor, not the viewport itself.