small optimisation, working

This commit is contained in:
Mathieu PATUREL
2017-01-07 16:09:36 +11:00
parent c605ffb3db
commit 3dcaed0ede
4 changed files with 8 additions and 5 deletions

View File

@ -12,11 +12,13 @@ from .functions import *
class MarkdownLivePreviewListener(sublime_plugin.EventListener): class MarkdownLivePreviewListener(sublime_plugin.EventListener):
def on_modified(self, view): def on_modified(self, view):
window = view.window() if not is_markdown_view(view):
return
vsettings = view.settings() vsettings = view.settings()
if vsettings.get(PREVIEW_ENABLED): if vsettings.get(PREVIEW_ENABLED):
id = vsettings.get(PREVIEW_ID) id = vsettings.get(PREVIEW_ID)
preview = get_view_from_id(window, id) preview = get_view_from_id(view.window(), id)
if id is None or preview is None: if id is None or preview is None:
preview = create_preview(view) preview = create_preview(view)
sublime.set_timeout_async(lambda: show_html(view, preview), 1000) sublime.set_timeout_async(lambda: show_html(view, preview), 1000)

View File

@ -75,6 +75,8 @@ def get_view_content(view):
return view.substr(sublime.Region(0, view.size())) return view.substr(sublime.Region(0, view.size()))
def get_view_from_id(window, id): def get_view_from_id(window, id):
if not isinstance(id, int):
return
for view in window.views(): for view in window.views():
if view.id() == id: if view.id() == id:
return view return view

View File

@ -6,6 +6,5 @@ Hope you'll enjoy using MarkdownLivePreview!
![image](https://forum.sublimetext.com/uploads/st-forum-wide.png) ![image](https://forum.sublimetext.com/uploads/st-forum-wide.png)
![GitHub](https://octodex.github.com/images/jetpacktocat.png) [GitHub](https://octodex.github.com/images/jetpacktocat.png)
This is a test, and it's still loading.