From 3bd8fd3da8e37fee57ff47eb43d3f97bfffa7c40 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Mon, 23 Sep 2024 12:55:49 +0800 Subject: feat: remove keydown events from dumbymap * events now handed by editor * this fix document.onkeydown reset when generatedMaps() called more than one time * apply "bind" to remove methods about user interaction from generateMaps() * refactor focusNextmap(), using array to store rendered maps BREAKING CHANGE: generateMaps() now return dumbymap Object, contains key elements and methods --- src/editor.mjs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/editor.mjs') diff --git a/src/editor.mjs b/src/editor.mjs index 897a0d1..4d8dbe8 100644 --- a/src/editor.mjs +++ b/src/editor.mjs @@ -8,6 +8,7 @@ import { createDocLinks } from './dumbymap.mjs' const HtmlContainer = document.querySelector(".DumbyMap") const textArea = document.querySelector(".editor textarea") +let dumbymap const toggleEditing = () => { if (document.body.getAttribute("data-mode") === "editing") { @@ -152,7 +153,7 @@ const debounceForMap = (() => { return function(...args) { clearTimeout(timer); timer = setTimeout(() => { - generateMaps.apply(this, args) + dumbymap = generateMaps.apply(this, args) }, 1000); } })() @@ -548,10 +549,16 @@ document.onkeydown = (e) => { e.preventDefault() return null } - if (cm.hasFocus()) { - return null - } else { - return e + if (!cm.hasFocus()) { + e.preventDefault() + if (!dumbymap) return + + if (e.key === 'Tab') { + dumbymap.utils.focusNextMap(e.shiftKey) + } + if (e.key === 'x') { + dumbymap.utils.switchToNextLayout() + } } } -- cgit v1.2.3-70-g09d2