diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-08 11:50:50 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-08 12:04:29 +0800 |
commit | 49645530a2265fe33eef7d6fe6caf25542620447 (patch) | |
tree | 8f3462bfd9595139dfb18cf1c37176f89a1bc064 /src/editor.mjs | |
parent | fa041f0af1b534af2311963672f71777028fcd78 (diff) |
style: reformat code
Diffstat (limited to 'src/editor.mjs')
-rw-r--r-- | src/editor.mjs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index 0e073ef..2c2bc98 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -12,7 +12,7 @@ const dumbyContainer = document.querySelector('.DumbyMap') | |||
12 | const textArea = document.querySelector('.editor textarea') | 12 | const textArea = document.querySelector('.editor textarea') |
13 | let dumbymap | 13 | let dumbymap |
14 | 14 | ||
15 | const refLinkPattern = /\[([^\[\]]+)\]:\s+(.+)/ | 15 | const refLinkPattern = /\[([^\x5B\x5D]+)\]:\s+(.+)/ |
16 | let refLinks = [] | 16 | let refLinks = [] |
17 | 17 | ||
18 | /** | 18 | /** |
@@ -296,8 +296,8 @@ new window.MutationObserver(() => { | |||
296 | const setScrollLine = () => { | 296 | const setScrollLine = () => { |
297 | if (dumbyContainer.dataset.scrollLine) return | 297 | if (dumbyContainer.dataset.scrollLine) return |
298 | 298 | ||
299 | const lineNumber = cm.getCursor()?.line | 299 | const lineNumber = cm.getCursor()?.line ?? |
300 | ?? cm.lineAtHeight(cm.getScrollInfo().top, 'local') | 300 | cm.lineAtHeight(cm.getScrollInfo().top, 'local') |
301 | textArea.dataset.scrollLine = lineNumber | 301 | textArea.dataset.scrollLine = lineNumber |
302 | } | 302 | } |
303 | cm.on('scroll', setScrollLine) | 303 | cm.on('scroll', setScrollLine) |
@@ -324,7 +324,7 @@ new window.MutationObserver(() => { | |||
324 | if (!p) return | 324 | if (!p) return |
325 | 325 | ||
326 | const coords = cm.charCoords({ line: lineNumber, ch: 0 }) | 326 | const coords = cm.charCoords({ line: lineNumber, ch: 0 }) |
327 | p.scrollIntoView() | 327 | p.scrollIntoView({ inline: 'start' }) |
328 | const top = p.getBoundingClientRect().top | 328 | const top = p.getBoundingClientRect().top |
329 | dumbymap.htmlHolder.scrollBy(0, top - coords.top + 30) | 329 | dumbymap.htmlHolder.scrollBy(0, top - coords.top + 30) |
330 | }).observe(textArea, { | 330 | }).observe(textArea, { |
@@ -428,7 +428,7 @@ const menuForEditor = (event, menu) => { | |||
428 | if (context.dataset.mode !== 'editing') { | 428 | if (context.dataset.mode !== 'editing') { |
429 | const switchToEditingMode = new menuItem.Item({ | 429 | const switchToEditingMode = new menuItem.Item({ |
430 | innerHTML: '<strong>EDIT</strong>', | 430 | innerHTML: '<strong>EDIT</strong>', |
431 | onclick: () => context.dataset.mode = 'editing' | 431 | onclick: () => (context.dataset.mode = 'editing') |
432 | }) | 432 | }) |
433 | menu.appendChild(switchToEditingMode) | 433 | menu.appendChild(switchToEditingMode) |
434 | } | 434 | } |
@@ -1025,7 +1025,7 @@ cm.getWrapperElement().oncontextmenu = e => { | |||
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | /** HACK Sync selection from HTML to CodeMirror */ | 1027 | /** HACK Sync selection from HTML to CodeMirror */ |
1028 | document.addEventListener("selectionchange", () => { | 1028 | document.addEventListener('selectionchange', () => { |
1029 | if (cm.hasFocus()) { | 1029 | if (cm.hasFocus()) { |
1030 | return | 1030 | return |
1031 | } | 1031 | } |
@@ -1042,7 +1042,7 @@ document.addEventListener("selectionchange", () => { | |||
1042 | return | 1042 | return |
1043 | } | 1043 | } |
1044 | 1044 | ||
1045 | let texts = [content] | 1045 | const texts = [content] |
1046 | let sibling = selection.anchorNode.previousSibling | 1046 | let sibling = selection.anchorNode.previousSibling |
1047 | while (sibling) { | 1047 | while (sibling) { |
1048 | texts.push(sibling.textContent) | 1048 | texts.push(sibling.textContent) |
@@ -1064,12 +1064,12 @@ document.addEventListener("selectionchange", () => { | |||
1064 | cm.setSelection(cm.setCursor()) | 1064 | cm.setSelection(cm.setCursor()) |
1065 | return | 1065 | return |
1066 | } | 1066 | } |
1067 | index = cm.getLine(anchor.line).indexOf(text) | 1067 | index = cm.getLine(anchor.line).indexOf(text) |
1068 | } | 1068 | } |
1069 | anchor.ch = index + text.length | 1069 | anchor.ch = index + text.length |
1070 | }) | 1070 | }) |
1071 | 1071 | ||
1072 | cm.setSelection({ ...anchor, ch: anchor.ch - content.length }, anchor) | 1072 | cm.setSelection({ ...anchor, ch: anchor.ch - content.length }, anchor) |
1073 | } | 1073 | } |
1074 | }); | 1074 | }) |
1075 | // vim: sw=2 ts=2 foldmethod=marker foldmarker={{{,}}} | 1075 | // vim: sw=2 ts=2 foldmethod=marker foldmarker={{{,}}} |