diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-09 12:27:07 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-09 12:28:27 +0800 |
commit | 3cc1e78e2dcda4e703c20e5eb5e503f464373474 (patch) | |
tree | 7306bbeeae8b5cff07817afef96c66e74727f648 | |
parent | 4439bd7c682b7a96a15b170f4f5e3c7204e08867 (diff) |
feat: Remove spellcheck better
-rw-r--r-- | src/editor.mjs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index 281182e..f1c90ed 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -348,23 +348,24 @@ const addSuggestions = (currentLine, selection) => { | |||
348 | // }}} | 348 | // }}} |
349 | // EVENT: suggests for current selection {{{ | 349 | // EVENT: suggests for current selection {{{ |
350 | tinyEditor.addEventListener('selection', selection => { | 350 | tinyEditor.addEventListener('selection', selection => { |
351 | // To trigger click event on suggestions list, don't set suggestion list invisible | ||
352 | if (suggestionsEle.querySelector('.container__suggestion.focus:hover') !== null) { | ||
353 | return | ||
354 | } else { | ||
355 | suggestionsEle.style.display = 'none'; | ||
356 | } | ||
357 | |||
358 | // Check selection is inside editor contents | 351 | // Check selection is inside editor contents |
359 | const node = selection?.anchor?.node | 352 | const node = selection?.anchor?.node |
360 | if (!node) return | 353 | if (!node) return |
361 | 354 | ||
355 | // FIXME Better way to prevent spellcheck across editor | ||
362 | // Get HTML element for current selection | 356 | // Get HTML element for current selection |
363 | const element = node instanceof HTMLElement | 357 | const element = node instanceof HTMLElement |
364 | ? node | 358 | ? node |
365 | : node.parentNode | 359 | : node.parentNode |
366 | element.setAttribute('spellcheck', 'false') | 360 | element.setAttribute('spellcheck', 'false') |
367 | 361 | ||
362 | // To trigger click event on suggestions list, don't set suggestion list invisible | ||
363 | if (suggestionsEle.querySelector('.container__suggestion.focus:hover') !== null) { | ||
364 | return | ||
365 | } else { | ||
366 | suggestionsEle.style.display = 'none'; | ||
367 | } | ||
368 | |||
368 | // Do not show suggestion by attribute | 369 | // Do not show suggestion by attribute |
369 | if (suggestionsEle.getAttribute('data-keep-close') === 'true') { | 370 | if (suggestionsEle.getAttribute('data-keep-close') === 'true') { |
370 | suggestionsEle.setAttribute('data-keep-close', 'false') | 371 | suggestionsEle.setAttribute('data-keep-close', 'false') |