Skip to content

Commit 11207ef

Browse files
thomasahleclaude
andcommitted
Fix transition buttons: use MoveCursorToTransition inject_message
The WCP text command 'transition_next' requires an explicit alphabetic variable label argument (e.g. 'transition_next a') — sending it bare fails to parse and does nothing. Switch to sending MoveCursorToTransition directly as a JSON inject_message with the explicit VisibleItemIndex from _focusedVisibleIdx. This: - Specifies the variable explicitly, so no focused-item state is needed - Avoids the async WCP command-file fetch entirely - Eliminates the iframe-blur race condition Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8f70c3b commit 11207ef

1 file changed

Lines changed: 13 additions & 26 deletions

File tree

src/lib/components/WaveformViewer.svelte

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,32 +116,19 @@
116116
if (!cw) return;
117117
118118
if (cmd === 'transition_next' || cmd === 'transition_previous') {
119-
// Dispatch a synthetic arrow-key event directly to the Surfer iframe
120-
// (same-origin access). This mirrors what happens when the user presses
121-
// ← / → with the iframe focused, and avoids the async race between the
122-
// WCP command-file fetch and the iframe-blur event clearing Surfer's
123-
// focused-variable state.
124-
//
125-
// We also re-send FocusItem first so Surfer's focused variable is correct
126-
// even if it was cleared by the blur event. postMessage is async, so we
127-
// delay the key dispatch by 50 ms to ensure FocusItem is processed by
128-
// Surfer before the keyboard event fires.
129-
if (_focusedVisibleIdx !== undefined) {
130-
surferMsg(cw, { FocusItem: _focusedVisibleIdx });
131-
}
132-
const key = cmd === 'transition_next' ? 'ArrowRight' : 'ArrowLeft';
133-
setTimeout(() => {
134-
const el = iframeEl;
135-
if (!el) return;
136-
const canvas = el.contentDocument?.getElementById('the_canvas_id');
137-
const target = canvas ?? el.contentWindow;
138-
if (!target) return;
139-
// Create the event in the iframe's realm to avoid cross-realm prototype issues.
140-
const IframeKBEvent = el.contentWindow?.KeyboardEvent ?? KeyboardEvent;
141-
target.dispatchEvent(
142-
new IframeKBEvent('keydown', { key, code: key, bubbles: true, cancelable: true })
143-
);
144-
}, 50);
119+
// The WCP text command `transition_next` requires an explicit alphabetic
120+
// variable label argument — sending it bare does nothing. Instead, send
121+
// MoveCursorToTransition as a direct JSON inject_message with the explicit
122+
// VisibleItemIndex. This bypasses the WCP text-file fetch, the iframe-blur
123+
// race, and any focused-item state dependency.
124+
if (_focusedVisibleIdx === undefined) return;
125+
surferMsg(cw, {
126+
MoveCursorToTransition: {
127+
next: cmd === 'transition_next',
128+
variable: _focusedVisibleIdx,
129+
skip_zero: false,
130+
},
131+
});
145132
return;
146133
}
147134

0 commit comments

Comments
 (0)