fix: 恢复全局快捷键自动复制触发限制#530
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to prevent duplicate global shortcut triggers by tracking the triggering state (isGlobalShortcutTriggering). It also adds a mechanism to wait for modifier keys to be released before capturing selected text context, preventing modifier keys from interfering with the native selection retrieval. This is implemented in DoubleTapManager via waitForModifierKeysReleased. The review feedback points out a potential linter issue in waitForModifierKeysReleased where wrappedResolve is referenced before its declaration, and suggests restructuring the promise initialization to avoid this.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| waitForModifierKeysReleased(timeoutMs: number = 1000): Promise<boolean> { | ||
| if (!this.hasPressedModifierKey()) { | ||
| return Promise.resolve(true) | ||
| } | ||
|
|
||
| return new Promise((resolve) => { | ||
| let timer: ReturnType<typeof setTimeout> | null = setTimeout(() => { | ||
| this.modifierKeysReleasedWaiters.delete(wrappedResolve) | ||
| resolve(false) | ||
| }, timeoutMs) | ||
|
|
||
| const wrappedResolve = (released: boolean) => { | ||
| if (timer) { | ||
| clearTimeout(timer) | ||
| timer = null | ||
| } | ||
| resolve(released) | ||
| } | ||
|
|
||
| this.modifierKeysReleasedWaiters.add(wrappedResolve) | ||
| }) | ||
| } |
There was a problem hiding this comment.
在 waitForModifierKeysReleased 方法中,wrappedResolve 在 setTimeout 的回调函数中被引用,但它的声明(const wrappedResolve = ...)却在 setTimeout 调用之后。虽然在运行时因为 setTimeout 是异步执行的,所以不会导致 Temporal Dead Zone (TDZ) 报错,但这种“在声明前引用”的代码结构不符合词法作用域的最佳实践,并且容易触发静态代码分析工具或 Linter(如 no-use-before-define)的警告。\n\n建议通过先声明 timer,再声明 wrappedResolve,最后为 timer 赋值的方式,优雅地解决这个循环引用的问题。
waitForModifierKeysReleased(timeoutMs: number = 1000): Promise<boolean> {\n if (!this.hasPressedModifierKey()) {\n return Promise.resolve(true)\n }\n\n return new Promise((resolve) => {\n let timer: ReturnType<typeof setTimeout> | null = null\n\n const wrappedResolve = (released: boolean) => {\n if (timer) {\n clearTimeout(timer)\n timer = null\n }\n resolve(released)\n }\n\n timer = setTimeout(() => {\n this.modifierKeysReleasedWaiters.delete(wrappedResolve)\n resolve(false)\n }, timeoutMs)\n\n this.modifierKeysReleasedWaiters.add(wrappedResolve)\n })\n }
恢复了修饰键抬起判定,防止自动复制时导致触发错误的快捷键