gsantner / markor

Text editor - Notes & ToDo (for Android) - Markdown, todo.txt, plaintext, math, ..
https://github.com/gsantner/markor/discussions/2269
Other
3.85k stars 370 forks source link

Add support for scroll position sync #2404

Open guanglinn opened 2 months ago

guanglinn commented 2 months ago

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

This feature supports:

The related issues:

2373 #2189 #1070 #1060 #679.

guanglinn commented 2 months ago

You can see the demonstration ↓

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

gsantner commented 2 months ago

has conflicts

guanglinn commented 2 months ago

Conflicts are resolved :)

gsantner commented 2 months ago

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

guanglinn commented 2 months ago

Conflicts are resolved now.

guanglinn commented 2 months ago

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 is already a big progress for Markor can provide a rough position synch for Markdown.

As mentioned above, you can merge it first, it is stable now, and I will improve it if I have some better solutions later, or other contributors would make it perfect on this basis.

gsantner commented 2 months ago

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

guanglinn commented 2 months ago

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

gsantner commented 2 months ago

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 commented 2 months ago

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.

guanglinn commented 2 months ago

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

gsantner commented 1 month ago

@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.

wshoy commented 1 month ago

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.