Skip to content

Resolve the text input shortcut layout at runtime on wasm - #25395

Open
Cyannide wants to merge 1 commit into
bevyengine:mainfrom
Cyannide:wasm-shortcut-layout
Open

Resolve the text input shortcut layout at runtime on wasm#25395
Cyannide wants to merge 1 commit into
bevyengine:mainfrom
Cyannide:wasm-shortcut-layout

Conversation

@Cyannide

@Cyannide Cyannide commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Objective

COMMAND and WORD were compile-time consts keyed on cfg!(target_os) -- correct on native, wrong on wasm32, where target_os is "unknown" and one binary serves every host OS. macOS browser users got the Ctrl layout: Cmd-C/X/V/A matched no arm and were silently dropped, word navigation wanted Ctrl instead of Option, and the macOS-only arms (Cmd-arrow line start/end, Cmd-up/down text start/end) were cfg'd out entirely.

Solution

mac_host() keeps the cfg! answer off-wasm and asks the browser once (navigator.platform, UA fallback, cached in a OnceLock). The layout consts become locals and the affected patterns become guards; arm order and native behavior are unchanged, and wasm now picks the same arms a native build of the host OS would.

Fixes #25340 (the copy/cut/paste half of it; the Chrome permission prompt on paste is a separate issue in bevy_clipboard/winit).

Adds a wasm-only web-sys dependency (Window + Navigator) to bevy_ui_widgets.

Testing

  • The same change (backported to a patched 0.19) is shipping in a production
    wasm app; macOS browser testers confirmed Cmd-A/C/X/V went from silently
    dropped to working, with Option-arrow word nav behaving like a native mac
    build. Linux/Windows browsers keep the Ctrl layout.
  • Native behavior is unchanged by construction -- the guards reproduce the
    old const arms one for one, same order.
  • This branch: cargo check and clippy, x86_64 and wasm32-unknown-unknown.
  • To reproduce the original bug: serve the multiple_text_inputs example as
    wasm and try Cmd-C/V from a Mac browser (as in EditableText Copy / Paste does not work on Web targets #25340).

COMMAND and WORD were compile-time consts keyed on cfg!(target_os) --
correct on native, wrong on wasm32, where target_os is "unknown" and one
binary serves every host OS. macOS browser users got the Ctrl layout:
Cmd-C/X/V/A matched no arm and were silently dropped, word navigation
wanted Ctrl instead of Option, and the macOS-only arms (Cmd-arrow line
start/end, Cmd-up/down text start/end) were cfg'd out entirely.

mac_host() keeps the cfg! answer off-wasm and asks the browser once
(navigator.platform, UA fallback, cached in a OnceLock). The layout
consts become locals and the affected patterns become guards; arm order
and native behavior are unchanged, and wasm now picks the same arms a
native build of the host OS would.

Fixes bevyengine#25340 (the copy/cut/paste half of it; the Chrome permission
prompt on paste is a separate issue in bevy_clipboard/winit).
@kfc35 kfc35 added C-Bug An unexpected or incorrect behavior A-UI Graphical user interfaces, styles, layouts, and widgets O-Web Specific to web (WASM) builds A-Text Rendering and layout for characters S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 13, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in UI Aug 13, 2026
@kfc35 kfc35 added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Aug 13, 2026

@kfc35 kfc35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the issue for me on duck duck go! Nice!!!

And the fix itself looks good to me

@kfc35
kfc35 requested a review from ickshonpe August 13, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Text Rendering and layout for characters A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples O-Web Specific to web (WASM) builds S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

EditableText Copy / Paste does not work on Web targets

2 participants