From 3dcaed0edeb451586b0c32db93818899f6e91734 Mon Sep 17 00:00:00 2001 From: Mathieu PATUREL Date: Sat, 7 Jan 2017 16:09:36 +1100 Subject: [PATCH] small optimisation, working --- MarkdownLivePreview.py | 6 ++++-- README.md | 2 +- functions.py | 2 ++ sample.md | 3 +-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/MarkdownLivePreview.py b/MarkdownLivePreview.py index 824fe2a..da0ed57 100644 --- a/MarkdownLivePreview.py +++ b/MarkdownLivePreview.py @@ -12,11 +12,13 @@ from .functions import * class MarkdownLivePreviewListener(sublime_plugin.EventListener): def on_modified(self, view): - window = view.window() + if not is_markdown_view(view): + return + vsettings = view.settings() if vsettings.get(PREVIEW_ENABLED): 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: preview = create_preview(view) sublime.set_timeout_async(lambda: show_html(view, preview), 1000) diff --git a/README.md b/README.md index 0729496..fc0b67d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MarkdownLivePreview +# MarkdownLivePreview This is a sublime text **3** plugin that allows you to preview your markdown instantly *in* it! diff --git a/functions.py b/functions.py index 93a05ec..04490be 100644 --- a/functions.py +++ b/functions.py @@ -75,6 +75,8 @@ def get_view_content(view): return view.substr(sublime.Region(0, view.size())) def get_view_from_id(window, id): + if not isinstance(id, int): + return for view in window.views(): if view.id() == id: return view diff --git a/sample.md b/sample.md index ffae9c9..16aef8a 100644 --- a/sample.md +++ b/sample.md @@ -6,6 +6,5 @@ Hope you'll enjoy using MarkdownLivePreview! ![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.