aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/editor.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/editor.mjs')
-rw-r--r--src/editor.mjs28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/editor.mjs b/src/editor.mjs
index 3dc5df7..6f046e6 100644
--- a/src/editor.mjs
+++ b/src/editor.mjs
@@ -10,17 +10,17 @@ const HtmlContainer = document.querySelector('.DumbyMap');
10const textArea = document.querySelector('.editor textarea'); 10const textArea = document.querySelector('.editor textarea');
11let dumbymap; 11let dumbymap;
12 12
13new MutationObserver(() => { 13new MutationObserver(mutations => {
14 if ( 14 const mutation = mutations.at(-1);
15 document.querySelector('[data-mode]').getAttribute('data-mode') === 15 const mode = mutation.target.getAttribute('data-mode');
16 'editing' && 16 const layout = HtmlContainer.getAttribute('data-layout');
17 HtmlContainer.getAttribute('data-layout') !== 'normal' 17 if (mode === 'editing' && layout !== 'normal') {
18 ) {
19 HtmlContainer.setAttribute('data-layout', 'normal'); 18 HtmlContainer.setAttribute('data-layout', 'normal');
20 } 19 }
21}).observe(document.querySelector('[data-mode]'), { 20}).observe(document.querySelector('[data-mode]'), {
22 attributes: true, 21 attributes: true,
23 attributeFilter: ['data-mode'], 22 attributeFilter: ['data-mode'],
23 attributeOldValue: true,
24}); 24});
25const toggleEditing = () => { 25const toggleEditing = () => {
26 const mode = document.body.getAttribute('data-mode'); 26 const mode = document.body.getAttribute('data-mode');
@@ -280,7 +280,8 @@ window.onhashchange = () => {
280// Completion in Code Blok {{{ 280// Completion in Code Blok {{{
281// Elements about suggestions {{{ 281// Elements about suggestions {{{
282const menu = document.createElement('div'); 282const menu = document.createElement('div');
283menu.className = 'menu'; 283menu.className = 'menu editor-menu';
284menu.style.display = 'none';
284menu.onclick = () => (menu.style.display = 'none'); 285menu.onclick = () => (menu.style.display = 'none');
285new MutationObserver(() => { 286new MutationObserver(() => {
286 if (menu.style.display === 'none') { 287 if (menu.style.display === 'none') {
@@ -564,9 +565,12 @@ cm.on('cursorActivity', _ => {
564 } 565 }
565}); 566});
566cm.on('blur', () => { 567cm.on('blur', () => {
567 menu.style.display = 'none'; 568 if (menu.checkVisibility()) {
568 cm.getWrapperElement().classList.remove('focus'); 569 cm.focus() && cm.setCursor(anchor);
569 HtmlContainer.classList.add('focus'); 570 } else {
571 cm.getWrapperElement().classList.remove('focus');
572 HtmlContainer.classList.add('focus');
573 }
570}); 574});
571// }}} 575// }}}
572// EVENT: keydown for suggestions {{{ 576// EVENT: keydown for suggestions {{{
@@ -607,9 +611,9 @@ cm.on('keydown', (_, e) => {
607 currentSuggestion.onclick(); 611 currentSuggestion.onclick();
608 break; 612 break;
609 case 'Escape': 613 case 'Escape':
610 menu.style.display = 'none'; 614 if (!menu.checkVisibility()) break;
611 // Focus editor again 615 // Focus editor again
612 setTimeout(() => cm.focus() && cm.setCursor(anchor), 100); 616 setTimeout(() => (menu.style.display = 'none'), 50);
613 break; 617 break;
614 } 618 }
615}); 619});