aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/css/dumbymap.css2
-rw-r--r--src/dumbymap.mjs2
-rw-r--r--src/editor.mjs28
3 files changed, 17 insertions, 15 deletions
diff --git a/src/css/dumbymap.css b/src/css/dumbymap.css
index 4d0282b..84b6036 100644
--- a/src/css/dumbymap.css
+++ b/src/css/dumbymap.css
@@ -249,8 +249,8 @@ root {
249 display: flex; 249 display: flex;
250 justify-content: space-between; 250 justify-content: space-between;
251 padding: 0.5rem; 251 padding: 0.5rem;
252 position: relative;
253 252
253 position: relative;
254 z-index: 9999; 254 z-index: 9999;
255 255
256 cursor: pointer; 256 cursor: pointer;
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs
index cb528cd..5457959 100644
--- a/src/dumbymap.mjs
+++ b/src/dumbymap.mjs
@@ -274,8 +274,6 @@ export const generateMaps = (container, { delay, mapCallback }) => {
274 // }}} 274 // }}}
275 // Layout {{{ 275 // Layout {{{
276 // press key to switch layout 276 // press key to switch layout
277 const defaultLayout = layouts[0];
278 container.setAttribute('data-layout', defaultLayout.name);
279 277
280 // observe layout change 278 // observe layout change
281 const layoutObserver = new MutationObserver(mutations => { 279 const layoutObserver = new MutationObserver(mutations => {
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});