diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-14 19:31:23 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-15 00:27:48 +0800 |
commit | 8aadc8fd3b69fbd8a030e88426816c38ca32f4af (patch) | |
tree | 5fd455ef6376648034e28f38433ada8ca7252614 /src | |
parent | ae182b739a5aec6f2262891cb0d3e5bb85a1fe26 (diff) |
feat: Render maps directly be debounce
Diffstat (limited to 'src')
-rw-r--r-- | src/editor.mjs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index b88e488..b93f9ba 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -139,10 +139,30 @@ const completeForCodeBlock = (change) => { | |||
139 | } | 139 | } |
140 | } | 140 | } |
141 | 141 | ||
142 | // Re-render HTML by editor content | 142 | const debounceForMap = (() => { |
143 | cm.on("change", (_, change) => { | 143 | let timer = null; |
144 | |||
145 | return function(...args) { | ||
146 | let context = this; | ||
147 | |||
148 | clearTimeout(timer); | ||
149 | timer = setTimeout(() => { | ||
150 | generateMaps.apply(context, args) | ||
151 | }, 1000); | ||
152 | } | ||
153 | })() | ||
154 | |||
155 | const updateDumbyMap = () => { | ||
144 | markdown2HTML(HtmlContainer, editor.value()) | 156 | markdown2HTML(HtmlContainer, editor.value()) |
145 | createDocLinks(HtmlContainer) | 157 | createDocLinks(HtmlContainer) |
158 | debounceForMap(HtmlContainer) | ||
159 | } | ||
160 | |||
161 | updateDumbyMap() | ||
162 | |||
163 | // Re-render HTML by editor content | ||
164 | cm.on("change", (_, change) => { | ||
165 | updateDumbyMap() | ||
146 | addClassToCodeLines() | 166 | addClassToCodeLines() |
147 | completeForCodeBlock(change) | 167 | completeForCodeBlock(change) |
148 | }) | 168 | }) |