Add public Window API to drive copy/cut/paste of the focused text input; adopt it in the winit web backend - #12483
Draft
ruffsl wants to merge 1 commit into
Draft
Add public Window API to drive copy/cut/paste of the focused text input; adopt it in the winit web backend#12483ruffsl wants to merge 1 commit into
ruffsl wants to merge 1 commit into
Conversation
ruffsl
force-pushed
the
patch/wasm-clipboard-seam
branch
from
July 14, 2026 18:21
41ea9c2 to
505709a
Compare
`slint::Window` gains four methods that operate on the currently focused `TextInput`: - `copy_focused_text_selection() -> Option<SharedString>` - `cut_focused_text_selection() -> Option<SharedString>` - `paste_into_focused_text(&str) -> bool` - `has_focused_text_input() -> bool` Copy and cut return the selected text to the caller instead of writing it through `Platform::set_clipboard_text`, and paste takes the text as an argument instead of reading `Platform::clipboard_text`. This lets a custom backend service a clipboard operation from inside its own event handler. The motivating case is the web platform: the browser clipboard is asynchronous and reachable only from a `copy`/`cut`/`paste` `ClipboardEvent` fired during a user gesture, which the synchronous `Platform` clipboard hooks cannot satisfy — so the data has to flow through the event, not the `Platform` trait. `has_focused_text_input` reports whether a text input currently holds the focus, letting such a backend keep its clipboard-event target in sync with Slint — on the web, that means keeping a hidden editable element focused exactly while a text input is edited, since browsers only deliver clipboard (and IME) events to an editable context. Cut and paste honor the same read-only/disabled gate as the Cut/Paste keyboard shortcuts; copy stays ungated like the Copy shortcut. `TextInput::insert_text` is extracted from `paste_clipboard` so the paste path can insert externally-supplied text, and the winit web backend's `copy`/`cut`/`paste` handlers now drive these `Window` methods. That retires the `CURRENT_WASM_CLIPBOARD_DATA` thread-local shuttle: the wasm `Platform` clipboard hooks fall back to their default no-op implementations (nothing could reach them outside a clipboard event anyway) and the winit backend's `scoped-tls-hkt` dependency is dropped.
ruffsl
force-pushed
the
patch/wasm-clipboard-seam
branch
from
July 14, 2026 20:27
505709a to
3d35b01
Compare
Member
|
Just a thought: maybe these could be done with event such as |
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.
Disclosure: this change was developed and verified with the aid of an LLM.
Fixes #12482.
Adds three methods to
Window:copy_focused_text_selection,cut_focused_text_selection(both returning the selected text), andpaste_into_focused_text. Cut and paste honor the sameread_only()/enabled()gates as the keyboard shortcuts; copy is deliberately ungated, matching the Copy shortcut.TextInput::insert_textis extracted frompaste_clipboard(behavior-preserving; undo entries unchanged) so paste can insert caller-supplied text.The winit wasm backend's
copy/cut/pasteDOM handlers now call the new API instead of reaching intoWindowInner/TextInputprivates. This also removes theCURRENT_WASM_CLIPBOARD_DATAthread-local shuttle (now unreferenced) and itsscoped-tls-hktdependency, and fixes a latent hazard: the old handler held thefocus_itemRefCell borrow acrossTextInputcalls that can runedited/acceptedcallbacks into app code; the new helper drops the borrow before dispatch.Tests:
api/rs/slint/tests/window_focused_text_clipboard.rs— copy/cut/paste semantics, selection replacement, no-focus and empty-selection refusal, read-only (copy allowed, cut/paste refused), disabled, and multi-byte selection boundaries. CHANGELOG entry included (in anUnreleasedsection; will fold into master's on rebase).One disclosed question:
copy_focused_text_selectionreturns the real text ofinput-type: passwordfields, because the existing copy path has no password guard — this PR matches that behavior rather than silently diverging. Happy to add anInputType::Passwordrefusal here (or in both places) if that's preferred.