Repository navigation
arigl-web: Ctrl+V pastes the system clipboard (SDL cancelled its keydown) - #1541
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Emscripten_HandleKey(SDL_emscriptenevents.c, around line 440) cancels the keydown of every chord withctrlKey, because it counts any Ctrl chord as a navigation key. It does this even while text input is on.pasteevent fires.clipboard::get()reads the text the page last got from that event, so it stayed empty or stale.arigl_web_clipboard.mjsstep 4 dispatched aClipboardEvent('paste')itself, before sending the keys, so it passed all along.The fix
src/cvcGL/Clipboard.cpp: the glue now adds a capture-phasekeydownlistener onwindow. It runs before SDL's listener on the canvas. For Ctrl+V or Cmd+V (not with Alt), it replaces that one event'spreventDefaultwith 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 withnavigator.clipboard.writeText.clipboard::install()(new, ininc/cvc/gl/Clipboard.h): installs the page's side up front.ImGuiOverlaycalls it when it's made. Natively it does nothing.Tests
arigl_web_clipboard.mjsnow sends Ctrl+V with DevTools'pasteediting 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'sdefaultPrevented, and a failure message reports it.Local results. The fix was relinked into a single-threaded arigl-web built with the recipe's
build-wasm.shfrom cvcpkg's emsdk and wasm deps. That build is #1539's tree:Clipboard.cppis the same there as on master, and this branch's own build is left to CI's arigl-web job. Chrome 152 headless:arigl_web_mac_keys.mjspassed.install()in the overlay: step 5 fails.cvcgl_imgui_context_menu,cvcgl_imgui_overlay_keysandcvcgl_imgui_chat_widgetspass with the change.Not verified: Firefox and Safari, and real hardware keys. DevTools' paste command stands in for the key binding.