update preview when the user types
We don't have any delay in between updates (because i'm scared of threading), which has a few problem: 1. probably really sluggish on slow systems 2. probably slow for readmes with images (need to test) 3. flickers (the phantoms are updated too quickly, so sometimes it doesn't replace the old one smoothly) BUG: the preview doesn't load when we preview the markdown file
This commit is contained in:
27
utils.py
27
utils.py
@ -1,4 +1,27 @@
|
||||
import sublime
|
||||
# import sublime
|
||||
import time
|
||||
|
||||
def get_settings():
|
||||
return sublime.get_settings("MarkdownLivePreview.sublime-settings")
|
||||
return sublime.get_settings("MarkdownLivePreview.sublime-settings")
|
||||
|
||||
def min_time_between_call(timeout, on_block=lambda *args, **kwargs: None):
|
||||
""" Enforces a timeout between each call to the function
|
||||
timeout is in seconds
|
||||
"""
|
||||
last_call = 0
|
||||
|
||||
def outer(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
nonlocal last_call
|
||||
|
||||
if time.time() - last_call < timeout:
|
||||
time.sleep(timeout - (time.time() - last_call))
|
||||
|
||||
last_call = time.time()
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
return outer
|
||||
|
||||
@min_time_between_call(1)
|
||||
def hello():
|
||||
print(time.time())
|
||||
Reference in New Issue
Block a user