use timeout (1s) only when needed

The timeout are needed, at least on my computer, because ST crashes
otherwise
This commit is contained in:
Mathieu PATUREL
2017-01-05 16:05:27 +11:00
parent ed57d2813a
commit d2863e4a43
3 changed files with 14 additions and 4 deletions

View File

@ -132,6 +132,7 @@ def show_html(md_view, preview):
# set viewport position
return
# 0 < y < 1
y = md_view.text_to_layout(md_view.sel()[0].begin())[1] / md_view.layout_extent()[1]
vector = [0, y * preview.layout_extent()[1]]

View File

@ -16,8 +16,13 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
vsettings = view.settings()
if vsettings.get(PREVIEW_ENABLED):
id = vsettings.get(PREVIEW_ID)
if id is None or get_view_from_id(window, id) is None:
preview = get_view_from_id(window, id)
if id is None or preview is None:
preview = create_preview(view)
sublime.set_timeout(lambda: show_html(view, preview), 1000)
else:
show_html(view, preview)
return
def on_activated(self, view):
@ -27,8 +32,12 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
vsettings = view.settings()
if vsettings.get(PREVIEW_ENABLED):
id = vsettings.get(PREVIEW_ID)
if id is None or get_view_from_id(window, id) is None:
preview = get_view_from_id(window, id)
if id is None or preview is None:
preview = create_preview(view)
sublime.set_timeout(lambda: show_html(view, preview), 1000)
else:
show_html(view, preview)
return
# if view is preview

View File

@ -1,7 +1,7 @@
# DuckDuckGo - The Search engine you'll fall in love with
This is a test
This is a test, and this is pretty cool!
![image](http://afterishtar.pl/images/100x100.gif)
hello world
Hope you'll enjoy using MarkdownLivePreview!