diff options
| -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 | }) |