From 6a3dd6ac2f970ab826d78efe9638b88377ba45eb Mon Sep 17 00:00:00 2001 From: Mathieu PATUREL Date: Wed, 22 Mar 2017 17:30:32 +1100 Subject: [PATCH] :sparkles: update preview at the most once every 0.8s --- MarkdownLivePreview.py | 7 ++++++- setting_names.py | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/MarkdownLivePreview.py b/MarkdownLivePreview.py index bab988a..d1ef1be 100644 --- a/MarkdownLivePreview.py +++ b/MarkdownLivePreview.py @@ -2,6 +2,7 @@ import sublime import sublime_plugin +import time from .MLPApi import * from .setting_names import * @@ -46,6 +47,10 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener): def update(self, view): vsettings = view.settings() + now = time.time() + if now - vsettings.get(LAST_RUN, 0) < 0.8: + return + vsettings.set(LAST_RUN, now) if not vsettings.get(PREVIEW_ENABLED): return id = vsettings.get(PREVIEW_ID) @@ -58,7 +63,7 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener): show_html(view, preview) return view, preview - def on_modified(self, view): + def on_modified_async(self, view): if not is_markdown_view(view): # faster than getting the settings return self.update(view) diff --git a/setting_names.py b/setting_names.py index 0e1adfd..13bbc9a 100644 --- a/setting_names.py +++ b/setting_names.py @@ -7,3 +7,4 @@ IS_HIDDEN = 'is_hidden_markdown_live_preview' MD_VIEW_ID = 'markdown_live_preview_md_id' PREVIEW_WINDOW = 'markdown_live_preview_window' ON_OPEN = 'markdown_live_preview_on_open' +LAST_RUN = 'markdonw_live_preview_last_run'