fix: prevent clipboard restore from running when task is cancelled#10
Open
Ahmet-4955 wants to merge 1 commit into
Open
fix: prevent clipboard restore from running when task is cancelled#10Ahmet-4955 wants to merge 1 commit into
Ahmet-4955 wants to merge 1 commit into
Conversation
Using `try?` on `Task.sleep` silently swallows `CancellationError`,
causing the restore task to continue executing immediately after being
cancelled. This created a race condition where the old clipboard content
was restored before the target app had a chance to process the simulated
Cmd+V paste event — resulting in the previous clipboard content being
pasted instead of the transcribed text.
Replace `try?` with a proper `do/catch { return }` so that cancellation
causes the task to exit cleanly without triggering the clipboard restore.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Replace
try?withdo/catch { return }inschedulePasteboardRestoreto correctly handle Swift Task cancellation.Problem
try?onTask.sleepsilently swallowsCancellationError, causing the restore task to continue executing immediately after being cancelled — resulting in the old clipboard content being pasted instead of the transcribed text.Race condition:
performPaste()fires Cmd+Vtry?swallowsCancellationError→ task continues running immediatelyFix
Cancellation now causes the task to exit cleanly without triggering the clipboard restore.
Test plan
🤖 Generated with Claude Code