aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/editor.mjs
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-09-23 12:55:49 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-09-23 13:34:43 +0800
commit3bd8fd3da8e37fee57ff47eb43d3f97bfffa7c40 (patch)
treee58ac34f1e7195bb403299bd28e5f3af91550532 /src/editor.mjs
parent5eefd9c2e4f948cddecf313231afdc62aa1531cd (diff)
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
Diffstat (limited to 'src/editor.mjs')
-rw-r--r--src/editor.mjs17
1 files changed, 12 insertions, 5 deletions
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'
8 8
9const HtmlContainer = document.querySelector(".DumbyMap") 9const HtmlContainer = document.querySelector(".DumbyMap")
10const textArea = document.querySelector(".editor textarea") 10const textArea = document.querySelector(".editor textarea")
11let dumbymap
11 12
12const toggleEditing = () => { 13const toggleEditing = () => {
13 if (document.body.getAttribute("data-mode") === "editing") { 14 if (document.body.getAttribute("data-mode") === "editing") {
@@ -152,7 +153,7 @@ const debounceForMap = (() => {
152 return function(...args) { 153 return function(...args) {
153 clearTimeout(timer); 154 clearTimeout(timer);
154 timer = setTimeout(() => { 155 timer = setTimeout(() => {
155 generateMaps.apply(this, args) 156 dumbymap = generateMaps.apply(this, args)
156 }, 1000); 157 }, 1000);
157 } 158 }
158})() 159})()
@@ -548,10 +549,16 @@ document.onkeydown = (e) => {
548 e.preventDefault() 549 e.preventDefault()
549 return null 550 return null
550 } 551 }
551 if (cm.hasFocus()) { 552 if (!cm.hasFocus()) {
552 return null 553 e.preventDefault()
553 } else { 554 if (!dumbymap) return
554 return e 555
556 if (e.key === 'Tab') {
557 dumbymap.utils.focusNextMap(e.shiftKey)
558 }
559 if (e.key === 'x') {
560 dumbymap.utils.switchToNextLayout()
561 }
555 } 562 }
556} 563}
557 564