From 31f4119442d89dbb3aa541d547ab28ed515155bc Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sun, 14 Dec 2025 14:41:05 +0100 Subject: [PATCH] scripting: calling setFocus() without if now unfocuses active element --- CHANGELOG.md | 1 + resources/docs/docs/widgets/scripting.md | 2 +- src/client/widgets/scripts/script-vm.mjs | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b3b3962..2d48c2cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - user scripts are longer protected against infinite loop and the main window object may be reached (it's not supported to break out of scripting context, but resources are no longer wasted to prevent it) - `toolbar()` can now target menu actions by id instead of index - `getToolbar()` function added (returns the state of a menu entry toggle) + - calling `setFocus()` without argument now unfocuses current active element - midi - add `no_auto_note_off` option diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index ee65c8a8..45c94034 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -303,7 +303,7 @@ Reference: - `id` (optional): widget `id` as a string -Gives focus to a widget (ie input widget). +Gives focus to a widget (ie input widget). If `id` is omitted or falsy, currently focused element will be unfocused. *Built-in client only*: tells the operating system to give the focus to the client window diff --git a/src/client/widgets/scripts/script-vm.mjs b/src/client/widgets/scripts/script-vm.mjs index b4dc8b39..9f862b54 100644 --- a/src/client/widgets/scripts/script-vm.mjs +++ b/src/client/widgets/scripts/script-vm.mjs @@ -452,6 +452,8 @@ class ScriptVm extends Vm { if (widgets.length) { if (widgets[0].focus) widgets[0].focus() } + } else if (document.activeElement) { + document.activeElement.blur() } // built-in client only: electron will call window.focus()