Skip to content

arigl-web: Ctrl+V pastes the system clipboard (SDL cancelled its keydown) - #1541

Merged
transfix merged 1 commit into
masterfrom
fix/arigl-web-ctrl-v-paste
Nov 25, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/arigl-web-ctrl-v-paste

Conversation

@transfix

Copy link
Copy Markdown
Owner

In arigl-web under cvcGL's SDL window, Ctrl+V pasted nothing from the system clipboard into a field. This fixes that, and the clipboard test now exercises the real paste. Its old version passed only because it faked the paste event. The fix doesn't depend on #1536 or #1539. Don't merge without Joe's OK.

The bug

  • SDL cancels the keydown. SDL 3.4.12's Emscripten_HandleKey (SDL_emscriptenevents.c, around line 440) cancels the keydown of every chord with ctrlKey, because it counts any Ctrl chord as a navigation key. It does this even while text input is on.
  • No paste event. The browser doesn't paste for a cancelled Ctrl+V, so no paste event fires. clipboard::get() reads the text the page last got from that event, so it stayed empty or stale.
  • A second problem. The page's clipboard glue was installed by the first clipboard call. A Ctrl+V before any other clipboard use found no paste listener, even when the browser did paste.
  • Why the test didn't catch it. arigl_web_clipboard.mjs step 4 dispatched a ClipboardEvent('paste') itself, before sending the keys, so it passed all along.

The fix

  • src/cvcGL/Clipboard.cpp: the glue now adds a capture-phase keydown listener on window. It runs before SDL's listener on the canvas. For Ctrl+V or Cmd+V (not with Alt), it replaces that one event's preventDefault with a no-op. SDL still hands the key to ImGui, whose paste reads the text, and the browser runs its paste. Ctrl+C and Ctrl+X don't need the browser and are left as they were: ImGui copies with navigator.clipboard.writeText.
  • clipboard::install() (new, in inc/cvc/gl/Clipboard.h): installs the page's side up front. ImGuiOverlay calls it when it's made. Natively it does nothing.

Tests

arigl_web_clipboard.mjs now sends Ctrl+V with DevTools' paste editing command, the way a key binding does. The browser runs that command only when the keydown isn't cancelled. The test records each V keydown's defaultPrevented, and a failure message reports it.

  • Step 4: after the context menu's Paste is refused, the test changes the clipboard and presses Ctrl+V. The field must hold the new text, which shows that the refused read took nothing and that Ctrl+V pasted.
  • Step 5 (new): on a page that has just loaded, the first thing done is Ctrl+V into the field. It must paste.

Local results. The fix was relinked into a single-threaded arigl-web built with the recipe's build-wasm.sh from cvcpkg's emsdk and wasm deps. That build is #1539's tree: Clipboard.cpp is the same there as on master, and this branch's own build is left to CI's arigl-web job. Chrome 152 headless:

  • With the fix: clipboard 11/11 (V's keydown not cancelled), smoke 25/25, save passed, and cvcGL: Cmd as the shortcut key in a browser on a Mac (stacked on #1536) #1539's arigl_web_mac_keys.mjs passed.
  • Without the keydown listener: steps 4 and 5 fail. V's keydown is cancelled and the field gets nothing.
  • Without install() in the overlay: step 5 fails.
  • Native: cvcgl_imgui_context_menu, cvcgl_imgui_overlay_keys and cvcgl_imgui_chat_widgets pass with the change.

Not verified: Firefox and Safari, and real hardware keys. DevTools' paste command stands in for the key binding.

In arigl-web under SDL's window, Ctrl+V pasted nothing from the system
clipboard. SDL3's Emscripten_HandleKey cancels the keydown of every
Ctrl chord (it counts them as navigation keys), and a cancelled Ctrl+V
fires no paste event, so the text clipboard::get() reads from that
event never came.

The page's clipboard glue now listens for keydown in the capture phase
and makes Ctrl+V's (and Cmd+V's) cancel a no-op for that event: SDL
still hands the key to ImGui, and the browser pastes. The glue was also
installed only by the first clipboard call, so a first Ctrl+V found no
listener: clipboard::install(), which ImGuiOverlay calls when it is
made, installs it up front.

arigl_web_clipboard.mjs dispatched the paste event itself, so it passed
all along. It now presses Ctrl+V with DevTools' paste command, as a key
binding does, which the browser runs only when the keydown is not
cancelled, and a new step pastes first thing on a page just loaded.
@transfix
transfix enabled auto-merge (squash) November 25, 2026 20:11
@transfix
transfix merged commit c129186 into master Nov 25, 2026
54 of 55 checks passed
@transfix
transfix deleted the fix/arigl-web-ctrl-v-paste branch November 25, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant