update preview at the most once every 0.8s

This commit is contained in:
Mathieu PATUREL
2017-03-22 17:30:32 +11:00
parent 1542e5e898
commit 6a3dd6ac2f
2 changed files with 7 additions and 1 deletions

View File

@ -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)

View File

@ -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'