8000 js: leave the clipboard to the page unless the canvas has the focus by benface · Pull Request #701 · not-fl3/miniquad · GitHub
[go: up one dir, main page]

Skip to content

js: leave the clipboard to the page unless the canvas has the focus - #701

Open
benface wants to merge 1 commit into
not-fl3:masterfrom
benface:web-clipboard-when-focused
Open

benface wants to merge 1 commit into
not-fl3:masterfrom
benface:web-clipboard-when-focused

Conversation

@benface
@benface benface commented Nov 8, 2026
Copy link
Copy Markdown
Contributor

Why

On the web, gl.js listens for paste on the window and always calls preventDefault() and stopPropagation(), to hand the text to the app. So a page that puts any text field next to the canvas, such as a name field or a search box, can't paste into it: the browser never inserts the text. The copy and cut listeners would likewise replace whatever a field copies with the app's clipboard, once the app has set one, and they read the global event rather than the event they're given.

Change

copy, cut and paste reach the app only while its canvas is document.activeElement, as its keys do (they're listened for on the canvas). Anywhere else, gl.js leaves the event to the browser.

They're still listened for on the window rather than the canvas: Firefox sends a paste on a focused canvas to <body>, and every browser sends it to the page's selection when there is one, so a listener on the canvas would miss them.

Verification

In a macroquad game (CHOMP) built for the web, through Playwright on macOS, with two <input>s added to the page: text copied from one, then pasted into the other, then pasted with the canvas focused.

Before After
Paste into the field (Chromium, WebKit, Firefox) nothing the text
Paste with the canvas focused (Chromium, WebKit, Firefox) on_clipboard_paste on_clipboard_paste

🤖 Generated with Claude Code

The paste listener on the window took every paste on the page and
prevented the browser's own, so pasting into a text field next to the
canvas did nothing. Copy, cut and paste now reach the app only while
its canvas has the focus, as its keys do. They're still heard on the
window, since Firefox sends them to the body, and every browser to the
page's selection when there is one, rather than to the focused canvas.
Copy and cut also read the event they're given, not the global `event`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tigon32 added a commit to Tigon32/miniquad that referenced this pull request Nov 10, 2026
Tigon32 added a commit to Tigon32/miniquad that referenced this pull request Nov 10, 2026
…ot-fl3#698, not-fl3#602 (#1)

* Integrate upstream PRs not-fl3#701, not-fl3#698, not-fl3#602: js/gl.js

* ci: add targeted Rust WebAssembly and JS build checks

* ci: allow generating Cargo.lock for library builds
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

0