aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-10-01 20:18:17 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-10-01 20:22:11 +0800
commit6a4e8c07377d5d6df3b16c8f8756980a11a17178 (patch)
tree08faa079c5d7a22e7f6d5a0c885495c861386af1 /src
parent314eeb0a3f72ef94cfbd272489e7c162e6eda2c2 (diff)
fix: focus issue for editor
Now <ESC> and <F1> switch focus correctly
Diffstat (limited to 'src')
-rw-r--r--src/editor.mjs6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/editor.mjs b/src/editor.mjs
index 6f046e6..6f529ed 100644
--- a/src/editor.mjs
+++ b/src/editor.mjs
@@ -285,7 +285,6 @@ menu.style.display = 'none';
285menu.onclick = () => (menu.style.display = 'none'); 285menu.onclick = () => (menu.style.display = 'none');
286new MutationObserver(() => { 286new MutationObserver(() => {
287 if (menu.style.display === 'none') { 287 if (menu.style.display === 'none') {
288 menu.style.cssText = '';
289 menu.replaceChildren(); 288 menu.replaceChildren();
290 } 289 }
291}).observe(menu, { 290}).observe(menu, {
@@ -566,7 +565,7 @@ cm.on('cursorActivity', _ => {
566}); 565});
567cm.on('blur', () => { 566cm.on('blur', () => {
568 if (menu.checkVisibility()) { 567 if (menu.checkVisibility()) {
569 cm.focus() && cm.setCursor(anchor); 568 cm.focus()
570 } else { 569 } else {
571 cm.getWrapperElement().classList.remove('focus'); 570 cm.getWrapperElement().classList.remove('focus');
572 HtmlContainer.classList.add('focus'); 571 HtmlContainer.classList.add('focus');
@@ -600,7 +599,6 @@ cm.on('keydown', (_, e) => {
600 const focusSuggestion = e.shiftKey ? previousSuggestion : nextSuggestion; 599 const focusSuggestion = e.shiftKey ? previousSuggestion : nextSuggestion;
601 600
602 // Current editor selection state 601 // Current editor selection state
603 const anchor = cm.getCursor();
604 switch (e.key) { 602 switch (e.key) {
605 case 'Tab': 603 case 'Tab':
606 Array.from(menu.children).forEach(s => s.classList.remove('focus')); 604 Array.from(menu.children).forEach(s => s.classList.remove('focus'));
@@ -612,7 +610,7 @@ cm.on('keydown', (_, e) => {
612 break; 610 break;
613 case 'Escape': 611 case 'Escape':
614 if (!menu.checkVisibility()) break; 612 if (!menu.checkVisibility()) break;
615 // Focus editor again 613 // HACK delay menu display change for blur event, mark cm focus should keep
616 setTimeout(() => (menu.style.display = 'none'), 50); 614 setTimeout(() => (menu.style.display = 'none'), 50);
617 break; 615 break;
618 } 616 }