jbt / markdown-editor

Live (Github-flavored) Markdown Editor
http://jbt.github.com/markdown-editor
ISC License
2.83k stars 644 forks source link

chained scrollbars #4

Open ondrejsika opened 11 years ago

ondrejsika commented 11 years ago

Hi, this is the best markdown editor, that i view. i have only one comment. is it possible chain scrollbars for automatic move preview down if i write?

thanks Ondrej Sika

jbt commented 11 years ago

:+1: this is something I'd really like to do but I haven't yet figured out exactly the best way to do it yet. Definitely on the todo list though

ghost commented 10 years ago

Idea:

That gets you a height in lines to scroll on the code editor, to a height of the block element on the rendered pane.

I don't know what to do from there. This is a really complex feature.

carbontwelve commented 9 years ago

I was attempting to do this yesterday, although each implementation I tried didn't quite work right. I have seen chained scroll-bars elsewhere so may have a go at reverse engineering how they went about it to learn how it can be done here.

jbt commented 9 years ago

The simplest and most naïve way of implementing chaining would just be to link the %age scroll depth between the two views. Problem is that can go wrong when the markdown input is particularly smaller or larger than the output (eg a large image only takes up one line of input, but could be several hundred px high in the output).

The way some editors achieve it is to break the markdown into sections, but I haven't yet figured out a foolproof way to do this that wouldn't completely break in some scenarios (you can't go and stick <span> elements into the output anywhere you like - you have to be sure that you're putting them somewhere that won't affect the output).

Totally open to pull requests if someone cleverer than me can figure it out. Otherwise I'll carry on experimenting but I can't promise when I'll be able to get it to work.

Actually thinking about it, it might be possible to do something now that I've switched from marked to markdown-it, because it does give some information about source line numbers, and then could try and implement the solution suggested above...

ghost commented 9 years ago

I ask that chained scrollbars be toggleable, just in case that wan't thought of

jbt commented 9 years ago

Yeah good shout - I think that however they're implemented there's always scenarios where it'll be annoying, so definitely having a way to turn it off is a good idea