From 5776019016aee75b1e81dd751d6a54f69bfe8ea5 Mon Sep 17 00:00:00 2001 From: Chris Dumas Date: Thu, 27 Aug 2026 06:49:51 +0000 Subject: [PATCH] Fix Beat Prompt input focus --- js/h3_beat_prompt/index.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/js/h3_beat_prompt/index.js b/js/h3_beat_prompt/index.js index 3202969..97fa862 100644 --- a/js/h3_beat_prompt/index.js +++ b/js/h3_beat_prompt/index.js @@ -286,6 +286,18 @@ function setDirectiveValue(text, canonicalName, directiveNames, value) { return cleaned ? `${directiveLine}\n${cleaned}` : directiveLine; } +function isInteractiveTarget(target) { + return !!target?.closest?.("textarea, input, select, button, label"); +} + +function stopCanvasEvent(event) { + if (isInteractiveTarget(event.target)) event.stopPropagation(); +} + +function stopCanvasKeyboard(event) { + if (isInteractiveTarget(event.target)) event.stopImmediatePropagation(); +} + function renderUI(node) { const ui = node._dh3bpUI; if (!ui) return; @@ -328,7 +340,7 @@ function renderUI(node) { writeState(node, next); updateTextareaHeight(textarea); }); - textarea.addEventListener("keydown", (event) => event.stopImmediatePropagation()); + textarea.addEventListener("keydown", stopCanvasKeyboard); const applyTextUpdate = (nextText) => { const next = readState(node); @@ -492,6 +504,11 @@ function setupNode(node) { list.className = "dh3bp-list"; root.append(toolbar, list); + root.addEventListener("pointerdown", stopCanvasEvent); + root.addEventListener("mousedown", stopCanvasEvent); + root.addEventListener("click", stopCanvasEvent); + root.addEventListener("dblclick", stopCanvasEvent); + root.addEventListener("keydown", stopCanvasKeyboard, true); node._dh3bpUI = { root, list }; const widget = node.addDOMWidget("dumas_h3_beat_prompt", "custom", root, {