Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/wrap-text/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export async function wrapSelectedText(left: string, right: string = left) {
const previousClipboard = await Clipboard.read();

await Clipboard.paste(wrapped);
await new Promise((resolve) => setTimeout(resolve, 200));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Hardcoded delay may be brittle on slow systems

The 200ms delay is a reasonable heuristic that works for most apps under normal conditions. However, on heavily loaded machines or with applications that have slower paste handling, the race condition could still occur. There's no deterministic way to know when the target app has processed the Cmd+V, so a time-based delay is a practical approach here — but it may be worth documenting this limitation in a comment so future maintainers understand why this number was chosen.

Suggested change
await new Promise((resolve) => setTimeout(resolve, 200));
await new Promise((resolve) => setTimeout(resolve, 200)); // Give the target app time to process Cmd+V before clipboard is restored
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/wrap-text/src/utils.ts
Line: 18

Comment:
**Hardcoded delay may be brittle on slow systems**

The 200ms delay is a reasonable heuristic that works for most apps under normal conditions. However, on heavily loaded machines or with applications that have slower paste handling, the race condition could still occur. There's no deterministic way to know when the target app has processed the `Cmd+V`, so a time-based delay is a practical approach here — but it may be worth documenting this limitation in a comment so future maintainers understand why this number was chosen.

```suggestion
    await new Promise((resolve) => setTimeout(resolve, 200)); // Give the target app time to process Cmd+V before clipboard is restored
```

How can I resolve this? If you propose a fix, please make it concise.


// Restore the previous clipboard content.
if (previousClipboard.text !== undefined) {
Expand Down
Loading