Skip to content

fix(clipboard): restore empty clipboard after dictation#48

Merged
missuo merged 1 commit into
missuo:mainfrom
erning:fix/clipboard-restore-empty
Apr 6, 2026
Merged

fix(clipboard): restore empty clipboard after dictation#48
missuo merged 1 commit into
missuo:mainfrom
erning:fix/clipboard-restore-empty

Conversation

@erning

@erning erning commented Mar 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

When the clipboard was empty before a dictation session, restoreIfUnchanged checked backedUpItems.count == 0 and returned early without clearing the clipboard. The dictated text was permanently left in the clipboard instead of being restored to the original empty state.

Root cause: the code could not distinguish "never backed up" (should skip restore) from "backed up an empty clipboard" (should clear contents to restore).

  • Add a hasBackup boolean flag set in backup and cleared after restore
  • scheduleRestoreAfterDelay: and restoreIfUnchanged now use hasBackup as the guard
  • restoreIfUnchanged always calls clearContents, then only calls writeObjects if the backup had items

Test plan

  • xcodebuild passes
  • Clear the clipboard completely, run a dictation session — after ~1.5s the clipboard returns to empty
  • Copy some text, run a dictation session — clipboard restores to the original text
  • Copy some text, run a dictation session, then manually paste something else within 1.5s — clipboard is not overwritten by the restore

Add hasBackup flag to distinguish "never backed up" from "backed up
but clipboard was empty". When original clipboard was empty, clear
contents on restore instead of silently leaving dictation text behind.

@missuo missuo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Clean fix for an edge case that would annoy users.

  • hasBackup flag correctly distinguishes "never backed up" from "backed up empty clipboard"
  • Guard changes from backedUpItems nil-check to hasBackup are consistent across both scheduleRestoreAfterDelay: and restoreIfUnchanged
  • Properly resets hasBackup = NO after restore and on clipboard-changed-since-write bail-out
  • Also properly cleans up backedUpItems = nil in the bail-out path (was missing before)

@missuo missuo merged commit 1bbc7c0 into missuo:main Apr 6, 2026
@erning erning deleted the fix/clipboard-restore-empty branch April 7, 2026 02:02
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