✨ update preview at the most once every 0.8s
This commit is contained in:
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import sublime
|
import sublime
|
||||||
import sublime_plugin
|
import sublime_plugin
|
||||||
|
import time
|
||||||
|
|
||||||
from .MLPApi import *
|
from .MLPApi import *
|
||||||
from .setting_names import *
|
from .setting_names import *
|
||||||
@ -46,6 +47,10 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
|||||||
|
|
||||||
def update(self, view):
|
def update(self, view):
|
||||||
vsettings = view.settings()
|
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):
|
if not vsettings.get(PREVIEW_ENABLED):
|
||||||
return
|
return
|
||||||
id = vsettings.get(PREVIEW_ID)
|
id = vsettings.get(PREVIEW_ID)
|
||||||
@ -58,7 +63,7 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
|||||||
show_html(view, preview)
|
show_html(view, preview)
|
||||||
return 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
|
if not is_markdown_view(view): # faster than getting the settings
|
||||||
return
|
return
|
||||||
self.update(view)
|
self.update(view)
|
||||||
|
|||||||
@ -7,3 +7,4 @@ IS_HIDDEN = 'is_hidden_markdown_live_preview'
|
|||||||
MD_VIEW_ID = 'markdown_live_preview_md_id'
|
MD_VIEW_ID = 'markdown_live_preview_md_id'
|
||||||
PREVIEW_WINDOW = 'markdown_live_preview_window'
|
PREVIEW_WINDOW = 'markdown_live_preview_window'
|
||||||
ON_OPEN = 'markdown_live_preview_on_open'
|
ON_OPEN = 'markdown_live_preview_on_open'
|
||||||
|
LAST_RUN = 'markdonw_live_preview_last_run'
|
||||||
|
|||||||
Reference in New Issue
Block a user