From 9c3cbff5f1026697df0b209d6add736e7d4d346a Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 24 Sep 2024 12:04:45 +0800 Subject: feat: add util "removeBlockFocus" --- src/dumbymap.mjs | 5 +++++ src/editor.mjs | 4 ++++ 2 files changed, 9 insertions(+) (limited to 'src') diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index 393cc08..595de5c 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs @@ -191,6 +191,10 @@ function focusNextBlock(reverse = false) { nextBlock.scrollIntoView({behavior: 'smooth', block: "nearest"}) } +function removeBlockFocus() { + this.blocks.forEach(b=>b.classList.remove('focus')) +} + export const generateMaps = (container, callback) => { container.classList.add('Dumby') const htmlHolder = container.querySelector('.SemanticHtml') ?? container @@ -211,6 +215,7 @@ export const generateMaps = (container, callback) => { focusNextMap: throttle(focusNextMap.bind(dumbymap), focusDelay.bind(dumbymap)), switchToNextLayout: throttle(switchToNextLayout.bind(dumbymap), 300), focusNextBlock: focusNextBlock.bind(dumbymap), + removeBlockFocus: removeBlockFocus.bind(dumbymap), } // LeaderLine {{{ diff --git a/src/editor.mjs b/src/editor.mjs index f4fadb4..35b1949 100644 --- a/src/editor.mjs +++ b/src/editor.mjs @@ -570,6 +570,10 @@ document.onkeydown = (e) => { e.preventDefault() dumbymap.utils.focusNextBlock(true) } + if (e.key === 'Escape') { + e.preventDefault() + dumbymap.utils.removeBlockFocus() + } } } -- cgit v1.2.3-70-g09d2