diff options
Diffstat (limited to 'src/editor.mjs')
-rw-r--r-- | src/editor.mjs | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index b2c4d54..168e66b 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -40,7 +40,8 @@ const editor = new EasyMDE({ | |||
40 | shortcuts: { | 40 | shortcuts: { |
41 | "map": "Ctrl-Alt-M", | 41 | "map": "Ctrl-Alt-M", |
42 | "debug": "Ctrl-Alt-D", | 42 | "debug": "Ctrl-Alt-D", |
43 | "toggleUnorderedList": "Ctrl-Shift-L", | 43 | "toggleUnorderedList": null, |
44 | "toggleOrderedList": null, | ||
44 | }, | 45 | }, |
45 | toolbar: [ | 46 | toolbar: [ |
46 | { | 47 | { |
@@ -156,12 +157,12 @@ const debounceForMap = (() => { | |||
156 | } | 157 | } |
157 | })() | 158 | })() |
158 | 159 | ||
159 | const afterMapRendered = (mapHolder) => { | 160 | const afterMapRendered = (_) => { |
160 | mapHolder.oncontextmenu = (event) => { | 161 | // mapHolder.oncontextmenu = (event) => { |
161 | event.preventDefault() | 162 | // event.preventDefault() |
162 | const lonLat = mapHolder.renderer.unproject([event.x, event.y]) | 163 | // const lonLat = mapHolder.renderer.unproject([event.x, event.y]) |
163 | // TODO... | 164 | // // TODO... |
164 | } | 165 | // } |
165 | } | 166 | } |
166 | 167 | ||
167 | const updateDumbyMap = () => { | 168 | const updateDumbyMap = () => { |
@@ -174,7 +175,6 @@ updateDumbyMap() | |||
174 | 175 | ||
175 | // Re-render HTML by editor content | 176 | // Re-render HTML by editor content |
176 | cm.on("change", (_, change) => { | 177 | cm.on("change", (_, change) => { |
177 | console.log('change', change.text) | ||
178 | updateDumbyMap() | 178 | updateDumbyMap() |
179 | addClassToCodeLines() | 179 | addClassToCodeLines() |
180 | completeForCodeBlock(change) | 180 | completeForCodeBlock(change) |
@@ -345,7 +345,6 @@ const handleTypingInCodeBlock = (anchor) => { | |||
345 | // }}} | 345 | // }}} |
346 | // FUNCTION: get suggestions by current input {{{ | 346 | // FUNCTION: get suggestions by current input {{{ |
347 | const getSuggestions = (anchor) => { | 347 | const getSuggestions = (anchor) => { |
348 | let suggestions = [] | ||
349 | const text = cm.getLine(anchor.line) | 348 | const text = cm.getLine(anchor.line) |
350 | 349 | ||
351 | // Clear marks on text | 350 | // Clear marks on text |
@@ -445,7 +444,7 @@ const getSuggestions = (anchor) => { | |||
445 | ) | 444 | ) |
446 | return rendererSuggestions.length > 0 ? rendererSuggestions : [] | 445 | return rendererSuggestions.length > 0 ? rendererSuggestions : [] |
447 | } | 446 | } |
448 | return suggestions | 447 | return [] |
449 | } | 448 | } |
450 | // }}} | 449 | // }}} |
451 | // {{{ FUNCTION: Show element about suggestions | 450 | // {{{ FUNCTION: Show element about suggestions |
@@ -505,11 +504,9 @@ cm.on("cursorActivity", (_) => { | |||
505 | }); | 504 | }); |
506 | // }}} | 505 | // }}} |
507 | // EVENT: keydown for suggestions {{{ | 506 | // EVENT: keydown for suggestions {{{ |
507 | const keyForSuggestions = ['Tab', 'Enter', 'Escape'] | ||
508 | cm.on('keydown', (_, e) => { | 508 | cm.on('keydown', (_, e) => { |
509 | 509 | if (!cm.hasFocus || !keyForSuggestions.includes(e.key) || suggestionsEle.style.display === 'none') return; | |
510 | // Only the following keys are used | ||
511 | const keyForSuggestions = ['Tab', 'Enter', 'Escape'].includes(e.key) | ||
512 | if (!keyForSuggestions || suggestionsEle.style.display === 'none') return; | ||
513 | 510 | ||
514 | // Directly add a newline when no suggestion is selected | 511 | // Directly add a newline when no suggestion is selected |
515 | const currentSuggestion = suggestionsEle.querySelector('.container__suggestion.focus') | 512 | const currentSuggestion = suggestionsEle.querySelector('.container__suggestion.focus') |
@@ -545,6 +542,13 @@ cm.on('keydown', (_, e) => { | |||
545 | document.onkeydown = (e) => { | 542 | document.onkeydown = (e) => { |
546 | if (e.altKey && e.ctrlKey && e.key === 'm') { | 543 | if (e.altKey && e.ctrlKey && e.key === 'm') { |
547 | toggleEditing() | 544 | toggleEditing() |
545 | e.preventDefault() | ||
546 | return null | ||
547 | } | ||
548 | if (cm.hasFocus()) { | ||
549 | return null | ||
550 | } else { | ||
551 | return e | ||
548 | } | 552 | } |
549 | } | 553 | } |
550 | 554 | ||