math2001 / MarkdownLivePreview

A Sublime Text 3 plugin to preview your markdown as you type
https://math2001.github.io/MarkdownLivePreview
MIT License
303 stars 37 forks source link

No "live" preview, just the first one. #11

Closed msieurtoph closed 7 years ago

msieurtoph commented 7 years ago

Hello Math, Thanks for this plugin.

The preview is working well (it opens the two-panels window when I open an md file)

BUT

When I type something in the left one (the md file), the preview is not updating anymore. There is a tiny delay, that proves something is processing, but the preview does not change.

FYI :

An idea about the cause of the issue ?

math2001 commented 7 years ago

Could you have a look in the console, to see if there is an error (view -> show console)?

msieurtoph commented 7 years ago

Hi No error in the console. I had a look to it already :)

math2001 commented 7 years ago

Is there comments in your file? (<!-- -->)

msieurtoph commented 7 years ago

Nope. And, as I said, if I save the file and reopen it, the preview is correct ... it is just that the "live rendering" seems not to work anymore.

msieurtoph commented 7 years ago

I tried with a new file (an empty one)

The preview is empty at the beginning (normal ;) ), but when I type something in the left panel, I see that the gutter with the line numbers in the right one expands to follow the height of the expected content ... but nothing is displayed in the "body"

math2001 commented 7 years ago

That's really weird... Are you using the default markdown syntax? In your markdown view, open up the console and paste this in:

'markdown' in view.scope_name(0)

it should print True

msieurtoph commented 7 years ago
>>> 'markdown' in view.scope_name(0)
True

The syntax I use seems very generic. When I tried with an empty md file, I just typed some random text without "signs".

The weird thing is that it seems to process and generate a content, because I clearly see the gutter height expand/reduce to follow the height of the expected content ... but nothing is displayed.

msieurtoph commented 7 years ago

And the scroll in right panel seems to follow the move too ...

math2001 commented 7 years ago

And the scroll in right panel seems to follow the move too ...

I don't get that... What do you mean?

What plugin to you have installed?

msieurtoph commented 7 years ago

I mean : if I typed multiline content, the scroll in the right panel moves to "focus" on the render of the line I am typing, even if the panel does not show anything.

I will try to make some cleaning in my packages and see if it changes something.

Hold the line ! :)

math2001 commented 7 years ago

oh! That might be because of the color scheme! If the color is the same as the background. It'd be really weird, but try to change your color scheme

msieurtoph commented 7 years ago

Ohoh ... Interresting fact :+1:

When I open an md file, I got the first render as I said. When I type something in left panel, modification does not show up in right-panel If I change the color theme just after ... I got the updated render ! If I type something again, the modification does not show up If I change color theme again, the right panel is updated again.

So I need to change color theme after each modification to get the render updated! So weird!

math2001 commented 7 years ago

What color scheme are you using? Maybe try to restart ST...

msieurtoph commented 7 years ago

Already tried to restart ST, a lot ;) And I use Monokai Bright theme, but it does not depend on the theme I use. I got the issue with all themes I tried.

msieurtoph commented 7 years ago

I tried some cleaning of my Packages : I kept :

But I keep having the problem.

math2001 commented 7 years ago

Can you send me a screenshot?

msieurtoph commented 7 years ago

of what ? the empty panel ?

math2001 commented 7 years ago

the mdview and the empty panel (two actually, when it's shown, and when there's nothing)

msieurtoph commented 7 years ago

image

I had the console panel ... to show how empty it is two :)

msieurtoph commented 7 years ago

I finally succeed to get what I want using this package instead : http://kenokabe.github.io/MarkdownLive/

It does not really fit my needs as I have to start a local server manually, using the node app command-line, because the automatic mode via ST does not work (maybe a track to explore for our issue : I got a ConnectionRefusedError [WinError 10061])

It's a shame your plugin does not work on my station, because it looks very sexier to have the two-panels directly inside the ST interface, without starting manually an external local server.

I hope you will fix this issue. Keep me in touch if you do have any idea or need me to test some stuffs.

msieurtoph commented 7 years ago

I tested the package on another computer and got the same result.

I finally noticed that changing the font size (by scrolling down and up the mouse when holding Ctrl key) trigs the rendering update ... I suppose it forces ST to update the panels views and it looks sufficient to make the rendering working... very very strange.

math2001 commented 7 years ago

How do you install MarkdownLivePreview? Was it window 7 to? Do the phantoms usually works?

math2001 commented 7 years ago

paste this in the console, a few times (up to get the previous command).

view.erase_phantoms('hello'); view.add_phantom('hello', sublime.Region(0), '<p>hello world!</p>', sublime.LAYOUT_BLOCK)

Change the HTML to see if it updates properly.

msieurtoph commented 7 years ago

Starting with an md file with two "test" lines in it...

Before: image

After: image

Both computer are running Win7 yes. And I install MLP through the Control Package, without any pb.. What is the Phantoms? Is it something about a virtual browser. If so, I never really used that kind of thing before: my use of ST is more like an advanced notepad than a complex IDE...

math2001 commented 7 years ago

The phantoms are these things you just added by typing the code I gave you in the console. They're part of Sublime Text api: they allow you to display (basic) HTML inside ST. If you build a python file for example, and there's an error, there'll be a red popup with the error rendered. That's what MDLP uses to display the markdown: it transforms the markdown to HTML, and show it in a phantom, in the right view.

And, if you update the test.md file, does the phantom hello world! go away?

msieurtoph commented 7 years ago

First test: Starting from the last screenshot: if I type "re-test" in the left panel (and save)....

image

And second test: Starting from the same screenshot than the first one. And if I try to modify the file in an external window... image Then (when focusing on the two-panels window)... image

math2001 commented 7 years ago

So, I'm confused now: does it still show the preview, but just doesn't update it, or stops completely (when you update the test.md file)

msieurtoph commented 7 years ago

When I open an md file and hit Alt + m : I got the correct preview in the two-panels window. But after that, the preview is never updated, whatever I do in the left panel.

The only thing that works is to change theme or change font size. These actions seems to "trigg" the preview update, for some reason I don't understand :

Here you can see that preview is not updated: image Then I change font-size and the preview gets updated: image

math2001 commented 7 years ago

I don't understand this at all, because the preview isn't even updated (by the plugin) when you change the font size... I'll keep digging

math2001 commented 7 years ago

Can you retry this, but make sure you change the html (the hello world!) (that's my fault, I edited the message afterwards)

view.erase_phantoms('hello'); view.add_phantom('hello', sublime.Region(0), '<p>hello world!</p>', sublime.LAYOUT_BLOCK)

And see if it gets updated properly.

msieurtoph commented 7 years ago

Yes, of course ... I guess I did it wrong the first time. Here it is: image

It only prints the first Hello World ... the Hello World 2 and 3 are not printed.

And If I change font-size, i got the last Hello Wolrd 3 printed: image

And after that if I update the md file (in the left panel), I got this: image

And if I change font-size again: image

Sorry for bugging you with this weird issue.

math2001 commented 7 years ago

No, it's okay. Now, that's really weird. These phantoms must work. Maybe, revert to a fresh stage.

here's a one line "trier" (you should get hello world! 4)

exec("for i in range(5):\n\tview.erase_phantoms('hello')\n\tview.add_phantom('hello', sublime.Region(0), '<p>hello world! {}</p>'.format(i), sublime.LAYOUT_BLOCK)")
msieurtoph commented 7 years ago

I am pretty sure your package works well. I am sure it process the preview (the HTML) and push it to the preview panel (so the phantoms are well instantiated and modified)... but I guess the "visual" part of the panel just needs to be "informed" that its content changed...

Following this idea: changing font-size "informs" the panel to update the "visual" part (because the font size change). And so the previous modifications are obviously taken into account ...

I just see your previous answer .... I do the test and post again...

msieurtoph commented 7 years ago

Here is what I get with your command line: image

And when i change font-size: image

I am pretty sure you miss a trigger, just to tell the panel to take into account the modifications you made to its content...

math2001 commented 7 years ago

The trigger is actually the view.erase_phantoms('hello'), which is suppose to remove all the phantoms that are named hello...

Oh, we're going to test only this. Run this in the console (after having run the command I just gave you):

view.erase_phantoms('hello')

The phantom should go away

msieurtoph commented 7 years ago

yes ... it went away

image

math2001 commented 7 years ago

Maybe I should add a timeout then... Let's do it in two step:

view.erase_phantoms('hello')

hit enter

view.add_phantom('hello', sublime.Region(0), '<p>hello world! 5</p>', sublime.LAYOUT_BLOCK)

And do those two commands again, but change the hello world! 5, and tell me if it's updated.

Maybe I just need to add a timeout...

msieurtoph commented 7 years ago

It printed "Hello world 5", then "hello World 6" :

image

msieurtoph commented 7 years ago

Oh ... you mean the erase function is asynchronous ? ... and it cannot add a new phantom if an existing has already the same name ?

math2001 commented 7 years ago

So, yeah, I need a timeout:

view.erase_phantoms('hello');sublime.set_timeout(lambda: view.add_phantom('hello', sublime.Region(0), '<p>hello world! 5</p>', sublime.LAYOUT_BLOCK), 250)

Oh ... you mean the erase function is asynchronous ?

I'm not sure, but it's a common problem with ST: to close a file when an other file is being closed, you need to add a timeout, otherwise it crashes for example.

and it cannot add a new phantom if an existing has already the same name ?

You can, but it'd add a new one, each time you edit your file (you'd end up with 100 phantoms if you type 100 chars ). It'd be good if you want to version your markdown file (probably not for the perf though) 😄

msieurtoph commented 7 years ago

OK, I think I get it. I hope the timeout will solve the pb.

Timeouts are not that nice (I dont like them). In javascript, you have callback that are called after the action is really done ... This is much better to deal with asynchronous tasks.

But wait a minute : it means my computers are slow to clear the phantoms ??? :(

However I found a post (where somebody was answering you, Math2001) about documentation of erase_phantoms and add_phantom ... He was hoping you'd rather use Phantom and PhantomSet classes instead. It cannot be the "nicer" solution ? https://forum.sublimetext.com/t/dev-build-3118/21270/74

I wait for the next release including the timeout or other solution (if you want me to test an alpha or beta before releasing : no pb. Give me a link the package and I'll install it and test this issue for you ...)

And thanks for your time and patience...

math2001 commented 7 years ago

I hope the timeout will solve the pb.

Did you try to run the code with the timeout?

To be honest, I learned to use phantom with the add_phantom since it was the example given. And, I forgot about using PhantomSet... 😖

So, here it is, using PhantomSet:

ps = sublime.PhantomSet(view, 'hello')

hit enter

ps.update([sublime.Phantom(sublime.Region(0), '<p>hello world! 6</p>', sublime.LAYOUT_BLOCK)])

Update the hello world! 6, and tell me if it works.

Sorry for keeping you waiting, I just had lunch...

msieurtoph commented 7 years ago

Excuse-me ... Got really busy today!

Here is the test using the PhantomSet command: It looks to work perfectly and updates the preview each time, without needing any other actions. image

Here is the test with the timeout: It works good too, except the delay inherent to the timeout value (250ms). image

As long as I can figure it out, the PhantomSet command seems to update instantly (no delay observed), so if I can give my opinion, and if you got the choice, I suggest you to go for the PhantomSet solution.

math2001 commented 7 years ago

YES!

I suggest you to go for the PhantomSet solution.

Of course! I'll push a new tag in minutes.

math2001 commented 7 years ago

Hum... Harder than I thought it'd be, because I have to save the phantoms in an object. (can't get it from the view, otherwise, I need a timeout 😆 ) But, I'm getting there.

math2001 commented 7 years ago

I pushed a new tag using those PhantomSet. Could you try and tell me if it works? v2.2.2

msieurtoph commented 7 years ago

How to ?

When I try to update my packages, I got image

math2001 commented 7 years ago

You need to wait a bit.

math2001 commented 7 years ago

If you want, you can remove this package, and install it with git, so you just have to run git pull

msieurtoph commented 7 years ago

Installed by removing package, adding your github repo in Control Package and reinstall the package. Easy!

And it works perfectly. Thank you very much for your time and your work!

You can close the issue.