Skip to main content

Module copy_button

Module copy_button 

Source
Expand description

Copying caller-supplied text, and saying truthfully whether it worked.

§What GPUI offers, and what it does not

gpui::App::write_to_clipboard takes a gpui::ClipboardItem and returns (). There is no Result, no error, and no callback: the platform layer takes the item and the call is over. So a button that showed a tick because write_to_clipboard returned would be showing a tick because a function with no failure mode did not fail, which is not evidence of anything.

The one thing GPUI does offer is gpui::App::read_from_clipboard, which returns Option<ClipboardItem>. That is real evidence, so it is what this component uses: it writes, reads back, and compares. A read that comes back empty, or comes back holding something else, is reported as a failure.

That check is honest but not complete, and the gap is stated rather than papered over: a platform where a write silently succeeds into a clipboard that a read then reports correctly, while some other application never sees it, would be indistinguishable from success here. Nothing in GPUI’s surface can tell that apart. What the check does catch is the common case — a clipboard that refused the write — and it never reports success on the strength of a call that cannot fail.

A host that knows better supplies its own CopyButton::copier, which returns a Result and whose failure text is shown verbatim.

§Why the confirmation does not time the failure out

A confirmation is transient: it says “that went through” and there is no reason for it to stay. A failure is not, for the reason docs/components.md gives for notifications — a failure nobody saw is a failure that was never reported. So the tick fades on a timer and the refusal stays until the next attempt replaces it.

Structs§

CopyButton
A button that copies caller-supplied text and confirms what happened.

Enums§

CopyEvent
What a copy button reports. The owner decides what any of it means.
CopyState
What the button is currently claiming.

Constants§

DEFAULT_CONFIRMATION
How long a confirmation stays before the button goes back to offering.

Functions§

verified_clipboard_copy
Writes to the platform clipboard and reads it back to check.