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

Add support for location synchronization between editor and preview #11

Closed
itsdani opened this issue Mar 8, 2017 · 10 comments
Closed

Comments

@itsdani
Copy link

itsdani commented Mar 8, 2017

It would be great if the preview jumped to the modified location if it is out of view. Similarly it would be really nice if the editor could be scrolled to a certain position by e.g. double clicking in the preview. Similar features are implemented in the Brackets editor for asciidoc, but I haven't seen it in any other editor/preview plugin.

@joaompinto
Copy link
Contributor

I am looking into this, the VSCode built-in extension for markdown files already does "scroll sync", but the code is somehow complex. I will do some more research on that code.

@diiigle
Copy link

diiigle commented May 22, 2017

+1

@zoeminghong
Copy link

wish

@danyill
Copy link
Contributor

danyill commented Mar 25, 2018

I am super keen for better syncing as well. My coding skills are quite modest but hopefully I can be a research assistant!

See asciidoctor/asciidoctor.js#127

  1. I think we need to run Asciidoctor with sourcemap=true
  2. We then call find_by which returns all nodes
  3. We then iterate across these and call source_location().line_no or similar. We then manipulate the object model to add this information.
  4. @rahmanusta has implemented a TreeProcessor (thanks!) which may be very similar to what is needed here in AsciidocFX which adds the line number to the role.

@joaompinto
Copy link
Contributor

@danyill thanks for the research, I was not aware of the sourcemap option.
The markdown built-in extension already provides this functionality (https://github.com/Microsoft/vscode/blob/master/extensions/markdown-language-features/src/markdownEngine.ts#L112) .

I am trying to reuse as much as possible code from the markdown extension, I will see if a similar logic can be implemented from the source_map metatata.

@joaompinto
Copy link
Contributor

Metadata is in 9f04dad

I had to look at the AsciidoctorJS source to figure how to use loadFile(), findBy(), getLineNumber(). addRole() .

I need to contribute to improve the documentation from https://github.com/asciidoctor/asciidoctor.js/blob/master/docs/manual.adoc , once this issue gets closed. I am missing the mapping/scroll part in VS Code :)

@joaompinto
Copy link
Contributor

joaompinto commented Mar 29, 2018

I have been looking into markdowns's synchronization code, and from my understanding, it depends on a feature (vscode.window.createWebview) which is only available from the "proposed API", which is restricted to internal VSCode extensions.

Will be tracking microsoft/vscode#28263, hoping that createWebview becomes available for general use.

@joaompinto
Copy link
Contributor

After some research I was able to figure a solution for the preview sync with source. Is not perfect but I was the best I could do :P . Those who have the skills please checkout from git, test it, and provide some feedback.

The preview is now "omnidoc", meaning you just need one view for multiple docs,t will get updated depending on the .adoc that is being edited.

The preview is "moved":

  • When text is changed
  • When text is selected

@joaompinto
Copy link
Contributor

I am confident on the new code, applied to the newer release.

@danyill
Copy link
Contributor

danyill commented Apr 1, 2018

@joaompinto

I've had a play and it looks good to me. Thanks!

I am interested in making the preview work correctly with Asciidoctor includes at some stage and will raise an issue for this. I'm playing around with some ways to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants