aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-09-13 23:15:10 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-09-15 00:27:48 +0800
commit8798cbf48e2c16fa8999147ffce481d4131ec6f2 (patch)
treefdc151a9488cfc5d4470373073eeef2e608b510b /src
parent9cf3a8dfed5c2cc06d3713e1c178ba24387a23ce (diff)
refactor: Use hidden element as anchor of suggestion list
Since suggestion list is not widget anymore, it could be seen outside of editor
Diffstat (limited to 'src')
-rw-r--r--src/editor.mjs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/editor.mjs b/src/editor.mjs
index 67df938..af3f629 100644
--- a/src/editor.mjs
+++ b/src/editor.mjs
@@ -180,6 +180,7 @@ window.onhashchange = () => {
180// Elements about suggestions {{{ 180// Elements about suggestions {{{
181const suggestionsEle = document.createElement('div') 181const suggestionsEle = document.createElement('div')
182suggestionsEle.classList.add('container__suggestions'); 182suggestionsEle.classList.add('container__suggestions');
183document.body.append(suggestionsEle)
183 184
184const rendererOptions = {} 185const rendererOptions = {}
185 186
@@ -448,11 +449,13 @@ const addSuggestions = (anchor, suggestions) => {
448 suggestionsEle.appendChild(option); 449 suggestionsEle.appendChild(option);
449 }); 450 });
450 451
451 cm.addWidget(anchor, suggestionsEle, true) 452 const widgetAnchor = document.createElement('div')
452 const rect = suggestionsEle.getBoundingClientRect() 453 cm.addWidget(anchor, widgetAnchor, true)
453 suggestionsEle.style.maxWidth = `calc(${window.innerWidth}px - ${rect.x}px - 2rem)`; 454 const rect = widgetAnchor.getBoundingClientRect()
455 suggestionsEle.style.left = `calc(${rect.left}px + 2rem)`;
456 suggestionsEle.style.top = `calc(${rect.bottom}px + 1rem)`;
457 suggestionsEle.style.maxWidth = `calc(${window.innerWidth}px - ${rect.x}px - 3rem)`;
454 suggestionsEle.style.display = 'block' 458 suggestionsEle.style.display = 'block'
455 suggestionsEle.style.transform = 'translate(2em, 1em)'
456} 459}
457// }}} 460// }}}
458// EVENT: Suggests for current selection {{{ 461// EVENT: Suggests for current selection {{{