feat(web): copy/paste in text fields via the browser clipboard (#346)
iced's clipboard rides window_clipboard, which has no wasm backend — a focused text_input captured Ctrl+C/V on the web and did nothing. Ctrl+V (captured, wasm only): read the async browser clipboard (the keypress is a user gesture, so it's permitted) and replay the text as synthetic KeyboardEvents on the winit canvas — the only route into a focused text_input, since iced exposes no insert-text operation. Control characters are dropped and the length is capped. The MText and inline-TEXT editors keep their dedicated paste paths (no double feed), and an unfocused Ctrl+V still runs PASTECLIP. Ctrl+C (captured, wasm only): a widget operation pairs each text_input with its focus state (iced fires both callbacks back-to-back on the same widget) to collect the focused field's visible text, then writes it with navigator.clipboard.writeText. Whole-field text, not the selection — iced doesn't expose the selected range. Native behaviour is unchanged. Closes #346 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
dd40e1f632
commit
5f08b77ebc
5 changed files with 147 additions and 0 deletions
|
|
@ -136,6 +136,13 @@ web-sys = { version = "0.3", features = [
|
|||
# Async clipboard read for paste into the text/MText editors (iced's own
|
||||
# clipboard read is a no-op on the web).
|
||||
"Clipboard",
|
||||
# Web copy/paste in plain text_input fields (#346): Ctrl+C writes the
|
||||
# focused field's text; Ctrl+V replays the clipboard as synthetic
|
||||
# KeyboardEvents on the canvas (the only route into a focused text_input).
|
||||
"KeyboardEvent",
|
||||
"KeyboardEventInit",
|
||||
"EventInit",
|
||||
"EventTarget",
|
||||
# Error banner (web_diag): forward wgpu/naga errors to the browser console
|
||||
# and inject a copyable DOM overlay (document.body → append_child).
|
||||
"console",
|
||||
|
|
|
|||
Loading…
Reference in a new issue