From 6a4e8c07377d5d6df3b16c8f8756980a11a17178 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 1 Oct 2024 20:18:17 +0800 Subject: fix: focus issue for editor Now and switch focus correctly --- src/editor.mjs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') 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'; menu.onclick = () => (menu.style.display = 'none'); new MutationObserver(() => { if (menu.style.display === 'none') { - menu.style.cssText = ''; menu.replaceChildren(); } }).observe(menu, { @@ -566,7 +565,7 @@ cm.on('cursorActivity', _ => { }); cm.on('blur', () => { if (menu.checkVisibility()) { - cm.focus() && cm.setCursor(anchor); + cm.focus() } else { cm.getWrapperElement().classList.remove('focus'); HtmlContainer.classList.add('focus'); @@ -600,7 +599,6 @@ cm.on('keydown', (_, e) => { const focusSuggestion = e.shiftKey ? previousSuggestion : nextSuggestion; // Current editor selection state - const anchor = cm.getCursor(); switch (e.key) { case 'Tab': Array.from(menu.children).forEach(s => s.classList.remove('focus')); @@ -612,7 +610,7 @@ cm.on('keydown', (_, e) => { break; case 'Escape': if (!menu.checkVisibility()) break; - // Focus editor again + // HACK delay menu display change for blur event, mark cm focus should keep setTimeout(() => (menu.style.display = 'none'), 50); break; } -- cgit v1.2.3-70-g09d2