langSwitcher icon indicating copy to clipboard operation
langSwitcher copied to clipboard

Clipboard is lost or not restored correctly after layout conversion

Open DSMorozov opened this issue 3 weeks ago • 0 comments

Hi! I ran into several clipboard problems with text conversion in AccessibilityService:

  1. Empty copy. The fixed 150ms sleep after ⌘C is sometimes too short, so the selection comes back empty and nothing is converted.
  2. Non-text clipboard is lost. savePasteboard() keeps only the first string type of each item, so images, files and rich text are gone after a conversion.
  3. Slow apps paste the old clipboard. Electron apps, browsers and remote desktops can read the pasteboard after the 300ms restore has already run, so they paste the user's previous clipboard instead of the converted text.
  4. A fresh copy gets overwritten. If the user copies something within 300ms of a conversion, the restore clobbers it.
  5. Back-to-back conversions. A second conversion before the restore saves our own converted text as the "original" clipboard, and the real one is lost.

I have a fix ready: wait for changeCount instead of sleeping, snapshot all types as raw data, restore after 1s and only if the pasteboard hasn't changed, and reuse the pending snapshot on repeated conversions. The full xcodebuild test suite passes (93 tests, 0 failures).

Would you accept a PR for this from a fork?

DSMorozov avatar Nov 07 '26 14:11 DSMorozov