fix: 使用序号机制修复超级面板剪贴板识别问题#431
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the clipboard monitoring logic in the SuperPanelManager to use a sequence-based tracking system instead of manual snapshots and comparisons. The ClipboardManager now maintains a sequence number for each copy event, and the SuperPanelManager uses this to reliably detect when a new copy operation has completed after simulating a keyboard shortcut. A potential race condition was identified in the getLastCopiedContent method where the calculation of the initial sequence could cause the system to miss a valid update if it occurs during the method execution.
| } | ||
|
|
||
| const initialTimestamp = this.lastCopiedContent?.timestamp ?? 0 | ||
| const initialSequence = Math.max(this.lastCopiedContent?.sequence ?? 0, minSequence ?? 0) |
There was a problem hiding this comment.
此处使用 Math.max 可能会引入竞态条件(Race Condition)。如果在第 823 行的检查之后到第 827 行的赋值之前,剪贴板内容发生了更新(导致 sequence 增加),initialSequence 将会被设置为更新后的序号。这会导致随后的循环开始等待一个更晚的更新,从而错过刚刚发生的这次更新,最终可能导致超时。建议在提供 minSequence 时直接使用它作为基准,或者在未提供时使用当前序号。
| const initialSequence = Math.max(this.lastCopiedContent?.sequence ?? 0, minSequence ?? 0) | |
| const initialSequence = minSequence !== undefined ? minSequence : (this.lastCopiedContent?.sequence ?? 0) |
修复先选中 文件/文本 后触发超级面板,不进行操作,再选相同内容重新进入超级面板时未触发对应链路问题