diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-24 12:04:45 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-24 12:17:22 +0800 |
commit | 9c3cbff5f1026697df0b209d6add736e7d4d346a (patch) | |
tree | 5012a9b3004c7757180458e7ece6700dc10848ea /src | |
parent | 3e441088ad9f5a98f0acda506bd03f7d1631cb0c (diff) |
feat: add util "removeBlockFocus"
Diffstat (limited to 'src')
-rw-r--r-- | src/dumbymap.mjs | 5 | ||||
-rw-r--r-- | src/editor.mjs | 4 |
2 files changed, 9 insertions, 0 deletions
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) { | |||
191 | nextBlock.scrollIntoView({behavior: 'smooth', block: "nearest"}) | 191 | nextBlock.scrollIntoView({behavior: 'smooth', block: "nearest"}) |
192 | } | 192 | } |
193 | 193 | ||
194 | function removeBlockFocus() { | ||
195 | this.blocks.forEach(b=>b.classList.remove('focus')) | ||
196 | } | ||
197 | |||
194 | export const generateMaps = (container, callback) => { | 198 | export const generateMaps = (container, callback) => { |
195 | container.classList.add('Dumby') | 199 | container.classList.add('Dumby') |
196 | const htmlHolder = container.querySelector('.SemanticHtml') ?? container | 200 | const htmlHolder = container.querySelector('.SemanticHtml') ?? container |
@@ -211,6 +215,7 @@ export const generateMaps = (container, callback) => { | |||
211 | focusNextMap: throttle(focusNextMap.bind(dumbymap), focusDelay.bind(dumbymap)), | 215 | focusNextMap: throttle(focusNextMap.bind(dumbymap), focusDelay.bind(dumbymap)), |
212 | switchToNextLayout: throttle(switchToNextLayout.bind(dumbymap), 300), | 216 | switchToNextLayout: throttle(switchToNextLayout.bind(dumbymap), 300), |
213 | focusNextBlock: focusNextBlock.bind(dumbymap), | 217 | focusNextBlock: focusNextBlock.bind(dumbymap), |
218 | removeBlockFocus: removeBlockFocus.bind(dumbymap), | ||
214 | } | 219 | } |
215 | 220 | ||
216 | // LeaderLine {{{ | 221 | // 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) => { | |||
570 | e.preventDefault() | 570 | e.preventDefault() |
571 | dumbymap.utils.focusNextBlock(true) | 571 | dumbymap.utils.focusNextBlock(true) |
572 | } | 572 | } |
573 | if (e.key === 'Escape') { | ||
574 | e.preventDefault() | ||
575 | dumbymap.utils.removeBlockFocus() | ||
576 | } | ||
573 | } | 577 | } |
574 | } | 578 | } |
575 | 579 | ||