small optimisation, working
This commit is contained in:
@ -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)
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -6,6 +6,5 @@ Hope you'll enjoy using MarkdownLivePreview!
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||

|
[GitHub](https://octodex.github.com/images/jetpacktocat.png)
|
||||||
|
|
||||||
This is a test, and it's still loading.
|
|
||||||
|
|||||||
Reference in New Issue
Block a user