fix(clipboard): restore empty clipboard after dictation#48
Merged
Conversation
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
approved these changes
Apr 6, 2026
missuo
left a comment
Owner
There was a problem hiding this comment.
LGTM. Clean fix for an edge case that would annoy users.
hasBackupflag correctly distinguishes "never backed up" from "backed up empty clipboard"- Guard changes from
backedUpItemsnil-check tohasBackupare consistent across bothscheduleRestoreAfterDelay:andrestoreIfUnchanged - Properly resets
hasBackup = NOafter restore and on clipboard-changed-since-write bail-out - Also properly cleans up
backedUpItems = nilin the bail-out path (was missing before)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the clipboard was empty before a dictation session,
restoreIfUnchangedcheckedbackedUpItems.count == 0and 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).
hasBackupboolean flag set inbackupand cleared after restorescheduleRestoreAfterDelay:andrestoreIfUnchangednow usehasBackupas the guardrestoreIfUnchangedalways callsclearContents, then only callswriteObjectsif the backup had itemsTest plan
xcodebuildpasses