diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-13 19:10:13 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-13 19:10:13 +0800 |
commit | 444e66905207efac253320d8558d5922d4f8291a (patch) | |
tree | 06cf6ec842f33911378311e8e1be58f87f5dc032 /src | |
parent | a9e16726b0e003ebb30e0c9bbeb8288a68810228 (diff) |
patch
Diffstat (limited to 'src')
-rw-r--r-- | src/editor.mjs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index 7cb0525..2df4279 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -173,7 +173,7 @@ const insideCodeblockForMap = (anchor) => { | |||
173 | return result | 173 | return result |
174 | } | 174 | } |
175 | // }}} | 175 | // }}} |
176 | // FUNCTION: Get renderer by cursor position in code block {{{ | 176 | // FUNCTION: Get Renderer by cursor position in code block {{{ |
177 | const getLineWithRenderer = (anchor) => { | 177 | const getLineWithRenderer = (anchor) => { |
178 | const currentLine = anchor.line | 178 | const currentLine = anchor.line |
179 | const match = (line) => cm.getLine(line).match(/^use: /) | 179 | const match = (line) => cm.getLine(line).match(/^use: /) |
@@ -182,25 +182,26 @@ const getLineWithRenderer = (anchor) => { | |||
182 | 182 | ||
183 | 183 | ||
184 | // Look backward/forward for pattern of used renderer: /use: .+/ | 184 | // Look backward/forward for pattern of used renderer: /use: .+/ |
185 | let ps = currentLine - 1 | 185 | let pl = currentLine - 1 |
186 | while (ps > 0 && insideCodeblockForMap(anchor)) { | 186 | while (pl > 0 && insideCodeblockForMap(anchor)) { |
187 | if (match(ps)) { | 187 | const text = cm.getLine(pl) |
188 | return ps | 188 | if (match(pl)) { |
189 | } else if (cm.getLine(ps).match(/^---/)) { | 189 | return pl |
190 | // If yaml doc separator is found | 190 | } else if (text.match(/^---|^````*/)) { |
191 | break | 191 | break |
192 | } | 192 | } |
193 | ps = ps - 1 | 193 | pl = pl - 1 |
194 | } | 194 | } |
195 | 195 | ||
196 | let ns = currentLine + 1 | 196 | let nl = currentLine + 1 |
197 | while (insideCodeblockForMap(anchor)) { | 197 | while (insideCodeblockForMap(anchor)) { |
198 | if (match(ns)) { | 198 | const text = cm.getLine(nl) |
199 | return ns | 199 | if (match(nl)) { |
200 | } else if (cm.getLine(ns).match(/^---/)) { | 200 | return nl |
201 | } else if (text.match(/^---|^````*/)) { | ||
201 | return null | 202 | return null |
202 | } | 203 | } |
203 | ns = ns + 1 | 204 | nl = nl + 1 |
204 | } | 205 | } |
205 | 206 | ||
206 | return null | 207 | return null |