markor icon indicating copy to clipboard operation
markor copied to clipboard

Add support for scroll position sync

Open guanglinn opened this issue 1 year ago • 13 comments

Add basic support for scroll position sync between Markdown preview (view-mode) and its source code (edit-mode).

This feature supports:

  • Sync position from edit to preview;
  • Sync position from preview to edit.

The related issues:
#2373 #2189 #1070 #1060 #679.

guanglinn avatar Sep 03 '24 11:09 guanglinn

You can see the demonstration ↓

https://github.com/user-attachments/assets/e2551f0e-7449-49d0-8a70-3ac22d22cf5f/

guanglinn avatar Sep 03 '24 16:09 guanglinn

has conflicts

gsantner avatar Sep 16 '24 20:09 gsantner

Conflicts are resolved :)

guanglinn avatar Sep 17 '24 02:09 guanglinn

I've merged your other PR to master as well, made conflicts again

gsantner avatar Sep 24 '24 23:09 gsantner

Conflicts are resolved now.

guanglinn avatar Sep 25 '24 01:09 guanglinn

Sure, from Edit to View, it works well for quite a lot common text blocks such as Headings, Bold, Italic, Blockquotes, Lists, Links, ... , but it works not quite well for some special text blocks.

I have tried to solve this, it's quite difficult, and I think this could be a big progress for Markor can provide a rough position synch for Markdown.

You can merge it first, it's stable now, and I will improve it if I have some better solutions later.

guanglinn avatar Sep 25 '24 02:09 guanglinn

What I would suggest for now: Save/Restore last webview scroll position after short delay (when blocks have the right rendered size).

As far I recall this has been before like that, but somehow it doesn't work currently on master either

gsantner avatar Sep 25 '24 02:09 gsantner

Can an option be added? Allow users to choose to let Markor restore last WebView scroll position, or sync WebView scroll position from Edit.

guanglinn avatar Sep 25 '24 03:09 guanglinn

I don't think it's neccassary. When scroll sync work good enough in praxis there is also the editor position saved/restored - so will be view-mode position when switiching to.

gsantner avatar Sep 25 '24 21:09 gsantner

Unfortunatley also keep in mind what I tried to say always - Markor is not only Markdown. This all relies on Markdown specific injections/adjusting the original.

This won't work for stuff that doesn't base on Markdown converter. So we need in any case such a fallback. And saving/restoring the view-mode scroll position should be viable for that.

It can't be resolved generically for everything and not easy to get much stable.

gsantner avatar Sep 25 '24 21:09 gsantner

Improvements: If we want to go back to the last view position, just long click the toolbar.

guanglinn avatar Sep 26 '24 05:09 guanglinn

@harshad1 @wshoy @elyahw may I ask about your thoughts, how good does it work on your device?

I watched guanglinns video again, but it just not works as good here at least in one way, which overall seems also worse then without the PR. In such case I don't feel too well either with bearing that by default to users.

Also very important to me: it's a feature for Markdown. People will rumble because not available/broken for others, issues inevitable.

gsantner avatar Oct 21 '24 21:10 gsantner

This feature feels great on an emulator, but unfortunately, it mostly doesn't work on my phone. When it does, it's only a couple times after reloading the file, and only from view mode to edit mode. Then it doesn't work at all.

On an emulator, when going from view mode to edit mode, it often jumps to the next line. Probably because of the word wrapping.

wshoy avatar Oct 25 '24 14:10 wshoy

PR has many conflicts (and some open discussionsI, converting it to draft for now. Please let me know when want to move on.

Thanks!

gsantner avatar Sep 18 '25 19:09 gsantner

PR has many conflicts (and some open discussionsI, converting it to draft for now. Please let me know when want to move on.

Thanks!

Thanks, Maybe it takes some time, maybe I need some help 😕

guanglinn avatar Sep 21 '25 13:09 guanglinn

No problem and understandable.

I also have quite little time available recently, and have to take care of my physical health.

gsantner avatar Sep 21 '25 13:09 gsantner

Yes, time and physical health are the most precious. This is not a smooth or successful PR for me, I closed it now. Maybe I will reopen it after sufficient improvement or open a new one.

guanglinn avatar Sep 21 '25 14:09 guanglinn