Skip to content

feat: preserve non-text clipboard content during paste-and-restore#1231

Open
egsok wants to merge 2 commits intocjpais:mainfrom
egsok:feat/clipboard-multiformat-clean
Open

feat: preserve non-text clipboard content during paste-and-restore#1231
egsok wants to merge 2 commits intocjpais:mainfrom
egsok:feat/clipboard-multiformat-clean

Conversation

@egsok
Copy link
Copy Markdown

@egsok egsok commented Apr 5, 2026

Problem

When using clipboard-based paste methods (Ctrl+V, Shift+Insert, etc.), Handy saves the clipboard, writes transcribed text, sends the paste keystroke, then restores the original clipboard content. Currently it only handles plain textread_text() returns an empty string for anything else.

This means if you had a screenshot, copied files, or rich HTML in the clipboard before transcribing, it was silently replaced with an empty string. Your clipboard content was lost.

Solution

Use arboard (already a transitive dependency via tauri-plugin-clipboard-manager, so zero extra compile cost) to detect and restore all clipboard formats:

Format Before After
Plain text
Images (screenshots) lost
HTML (rich text from browser) lost
Files (copied from Explorer/Finder) lost

Detection order is most-specific-first: files → image → HTML → text → empty. This prevents false matches (e.g., browser copies set both HTML and text fallback — text-first would lose formatting).

On Wayland, text restore still uses wl-copy for umlaut compatibility.

Files changed

  • src-tauri/Cargo.toml — add arboard as direct dependency
  • src-tauri/src/clipboard.rs — add SavedClipboard enum + save_clipboard()/restore_clipboard(), replace text-only save/restore in paste_via_clipboard()

Test plan

  • Copy screenshot (Win+Shift+S / Cmd+Shift+Ctrl+4) → transcribe → verify screenshot is still in clipboard
  • Copy plain text → transcribe → verify text is restored
  • Copy rich HTML from browser → transcribe → paste into rich editor → verify formatting preserved
  • Copy files in Explorer/Finder → transcribe → verify files still pasteable
  • Empty clipboard → transcribe → clipboard stays empty
  • Transcribed text still pastes correctly into target app
  • CopyToClipboard setting still works (leaves transcribed text in clipboard, no restore)

Save and restore images, HTML, files (not just text) when pasting
transcribed text via clipboard. Uses arboard directly for multi-format
clipboard access while keeping tauri plugin for writing transcription.

Detection order: files → image → HTML → text → empty.
Wayland text restore still uses wl-copy for umlaut compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cjpais
Copy link
Copy Markdown
Owner

cjpais commented Apr 5, 2026

Curious, have you tested all of these, just want to make sure

I've tested a branch that tried this before without success so just curious. I am open to this for sure though

@egsok
Copy link
Copy Markdown
Author

egsok commented Apr 5, 2026

@cjpais yes, sir! Tested every case (pics, html, files) on Win11.

authored a similar PR for Openwhispr recently (OpenWhispr/openwhispr#381), Handy is even better suited for this because of use of arboard (so we get support for random files from explorer as well, unlike Openwhispr).

@cjpais
Copy link
Copy Markdown
Owner

cjpais commented Apr 5, 2026

@egsok thanks for confirmation for Win11 testing, I will test on MacOS and get back

This definitely should be merged assuming it works well, it should address #921

Bug fixes are always super helpful so thank you!

@egsok
Copy link
Copy Markdown
Author

egsok commented Apr 5, 2026

@cjpais cool! let me know if anything needs fixing

@cjpais
Copy link
Copy Markdown
Owner

cjpais commented Apr 5, 2026

One possible thing to consider, in case of regressions is adding a toggle to change back to the old method. Could be done in debug potentially. I will test this myself first, I would prefer not to have this path.

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.

2 participants