aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dumbymap.mjs16
-rw-r--r--src/editor.mjs11
2 files changed, 26 insertions, 1 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs
index 01463c0..d7c822a 100644
--- a/src/dumbymap.mjs
+++ b/src/dumbymap.mjs
@@ -175,6 +175,22 @@ function switchToNextLayout(reverse = false) {
175 this.container.setAttribute("data-layout", nextLayout.name) 175 this.container.setAttribute("data-layout", nextLayout.name)
176} 176}
177 177
178function focusNextBlock(reverse = false) {
179 const blocks = this.blocks.filter(b=>b.checkVisibility({
180 contentVisibilityAuto: true,
181 opacityProperty: true,
182 visibilityProperty: true,
183 }))
184 const currentBlock = blocks.find(b=>b.classList.contains('focus'))
185 const currentIndex = blocks.indexOf(currentBlock)
186 const padding = reverse ? -1 : 1
187 const nextIndex = currentIndex === -1 ? 0 : (currentIndex + padding + blocks.length) % blocks.length
188 const nextBlock = blocks[nextIndex]
189 blocks.forEach(b=>b.classList.remove('focus'))
190 nextBlock?.classList?.add('focus')
191 nextBlock.scrollIntoView({behavior: 'smooth', block: "nearest"})
192}
193
178export const generateMaps = (container, callback) => { 194export const generateMaps = (container, callback) => {
179 container.classList.add('Dumby') 195 container.classList.add('Dumby')
180 const htmlHolder = container.querySelector('.SemanticHtml') ?? container 196 const htmlHolder = container.querySelector('.SemanticHtml') ?? container
diff --git a/src/editor.mjs b/src/editor.mjs
index 550f626..f4fadb4 100644
--- a/src/editor.mjs
+++ b/src/editor.mjs
@@ -552,15 +552,24 @@ document.onkeydown = (e) => {
552 return null 552 return null
553 } 553 }
554 if (!cm.hasFocus()) { 554 if (!cm.hasFocus()) {
555 e.preventDefault()
556 if (!dumbymap) return 555 if (!dumbymap) return
557 556
558 if (e.key === 'Tab') { 557 if (e.key === 'Tab') {
558 e.preventDefault()
559 dumbymap.utils.focusNextMap(e.shiftKey) 559 dumbymap.utils.focusNextMap(e.shiftKey)
560 } 560 }
561 if (e.key === 'x') { 561 if (e.key === 'x') {
562 e.preventDefault()
562 dumbymap.utils.switchToNextLayout() 563 dumbymap.utils.switchToNextLayout()
563 } 564 }
565 if (e.key === 'n') {
566 e.preventDefault()
567 dumbymap.utils.focusNextBlock()
568 }
569 if (e.key === 'p') {
570 e.preventDefault()
571 dumbymap.utils.focusNextBlock(true)
572 }
564 } 573 }
565} 574}
566 575