Skip to content

fix: make clipboard save/restore reliable during conversion - #10

Open
DSMorozov wants to merge 1 commit into
reg2005:mainfrom
DSMorozov:fix/clipboard-restore
Open

DSMorozov wants to merge 1 commit into
reg2005:mainfrom
DSMorozov:fix/clipboard-restore

Conversation

@DSMorozov

Copy link
Copy Markdown

fix: reliable clipboard save/restore during conversion

Relates to #9

Problem

  • A fixed 150ms sleep after ⌘C was sometimes too short, so the copy came back empty.
  • Only the first string type of each pasteboard item was saved, so images, files and rich text were lost.
  • The clipboard was restored after 300ms, before slow apps (Electron, browsers, remote desktops) had read it, so they pasted the user's old clipboard.
  • The restore overwrote anything the user copied in the meantime.
  • Two conversions in a row saved our own converted text as the "original" clipboard.

Fix

  • Poll changeCount after ⌘C (500ms timeout) instead of sleeping.
  • Snapshot all items and all types as raw data.
  • Restore after 1s, and only if the pasteboard has not changed since our paste.
  • Cancel a pending restore on the next conversion and reuse its snapshot.
  • Ignore the local build-cli/ output.

Testing

  • Full xcodebuild test suite passes locally (93 tests, 0 failures).
  • Manual check: convert text in a native app, a browser and an Electron app; check that the clipboard (including images) comes back afterwards.

🤖 Generated with Claude Code

- Wait for the pasteboard changeCount after ⌘C instead of a fixed 150ms sleep
- Snapshot all pasteboard items and types as raw data (not just the first string type)
- Delay clipboard restore to 1s so slow readers (Electron, browsers, remote desktops) get the converted text
- Skip the restore if the pasteboard changed since our paste, so a fresh user copy isn't overwritten
- On back-to-back conversions, cancel the pending restore and reuse its snapshot so the original clipboard isn't lost
- Ignore local build-cli/ output

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant