gedit-plugin-markdown_preview icon indicating copy to clipboard operation
gedit-plugin-markdown_preview copied to clipboard

Automatically keep the scroll position in sync

Open nekohayo opened this issue 3 years ago • 2 comments

It seems the markdown preview tries to manage scrolling but has some bugs in the way it handles it.

Depending on whether I'm typing characters (or new lines) or deleting them and the position at which I'm doing so (beginning, middle, or end of a long document), the behavior seems a bit erratic.

My general expectation would be that it would auto-scroll to the current typing position, maybe simply by scrolling when the user scrolls the main window with the mouse or the keyboard (i.e. when they use the arrow/PgUp/PgDown/Home/End keys), if

  • the scrolled view contains (or contained) the position of the current selection/text cursor position (i.e. maybe not if the user explicitly scrolled outside of the visible position of the text cursor because they want to preview another part of the document without the scroll resetting)
  • the scrollbar was already at the bottom and the user keeps appending text at the bottom of the document, or adding text somewhere else that increases the length (and thus scrolling) of the document. Currently this behavior seems to be a bit erratic, as you can see in the video below:

https://user-images.githubusercontent.com/479401/122784387-6eb5ff00-d280-11eb-8260-2d6a26b6b3dd.mp4

nekohayo avatar Jun 21 '21 15:06 nekohayo

the only thing the plugin manages is that, when you scroll to a given position in the preview (= a number of pixels from the top of the preview) with your mouse, this number of pixels is remembered and the position will be restored at the next reloading of the preview. At 0:05 we can even see a frame between the reloading of the preview and the reapplying of the position

the plugin is not aware at all of the position of the respective characters within the preview, and since the rendering is done by libraries i don't control, it just can't. Synchronizing the preview with the editor view is, sadly, probably not a possible future enhancement

the best i could do is that if you scrolled at the very end of the preview, the plugin could then try to scroll as down as possible at each reloading

maoschanz avatar Jun 21 '21 19:06 maoschanz

@maoschanz I think it should be possible to implement this feature, since the libraries have some extensions that can be enabled for including the source position in the output.

For example, pandoc has the sourcepos extension.

With cmark-gfm command the --sourcepos option can be enabled:

cmark-gfm --sourcepos example.md
<h1 data-sourcepos="2:1-2:7">Title</h1>
<h2 data-sourcepos="4:1-4:11">Subtitle</h2>
<p data-sourcepos="6:1-6:9">some text</p>

I could not find a python3-markdown extension for adding the source position in the output, but a new extension can be written.

Antonio-R1 avatar Nov 08 '22 16:11 Antonio-R1