From 11206039694f0a39d3c1ea1d20aaebc110c03b55 Mon Sep 17 00:00:00 2001 From: "PC-JASPER\\jasper" Date: Tue, 8 Sep 2026 15:22:45 +0200 Subject: [PATCH] fix: query block rename bugs --- .../QueryBuilderSelectorBlock.svelte | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/lib/components/query-builder/QueryBuilderSelectorBlock.svelte b/src/lib/components/query-builder/QueryBuilderSelectorBlock.svelte index 9488f20..7e31c79 100644 --- a/src/lib/components/query-builder/QueryBuilderSelectorBlock.svelte +++ b/src/lib/components/query-builder/QueryBuilderSelectorBlock.svelte @@ -63,6 +63,14 @@ add new query blocks, duplicate blocks, close clocks, select active blocks editingName = currentName; } + // The native `autofocus` attribute is unreliable for inputs mounted after + // initial page load, so the input never gains focus and never blurs on an + // outside click. This action focuses it explicitly when it is created. + function focusAndSelect(node: HTMLInputElement): void { + node.focus(); + node.select(); + } + function cancelRenameBlock(): void { editingBlockId = null; editingName = ''; @@ -111,6 +119,13 @@ add new query blocks, duplicate blocks, close clocks, select active blocks return; } + // Removing the focused input from the DOM (e.g. right after the finish + // button already committed and closed the editor) fires a blur on it too. + // Ignore that: this block is no longer the one being edited. + if (editingBlockId !== id) { + return; + } + commitRenameBlock(id); } @@ -199,7 +214,7 @@ add new query blocks, duplicate blocks, close clocks, select active blocks (editingName = event.currentTarget.value)} @@ -221,6 +236,11 @@ add new query blocks, duplicate blocks, close clocks, select active blocks class="query-block-icon-button" title={editingBlockId === block.id ? 'Finish editing name' : 'Edit name'} aria-label={editingBlockId === block.id ? 'Finish editing name' : 'Edit name'} + onmousedown={(event: MouseEvent) => { + // Keep focus on the input so this click can't trigger a blur-commit + // followed by the click handler re-opening the editor (two-click bug). + if (editingBlockId === block.id) event.preventDefault(); + }} onclick={(event) => { event.stopPropagation(); if (editingBlockId === block.id) {