Skip to content

fix: 恢复全局快捷键自动复制触发限制#530

Merged
lzx8589561 merged 1 commit into
ZToolsCenter:mainfrom
Particaly:fix/global-shortcut-auto-copy-guard
Jun 7, 2026
Merged

fix: 恢复全局快捷键自动复制触发限制#530
lzx8589561 merged 1 commit into
ZToolsCenter:mainfrom
Particaly:fix/global-shortcut-auto-copy-guard

Conversation

@Particaly

Copy link
Copy Markdown
Collaborator

恢复了修饰键抬起判定,防止自动复制时导致触发错误的快捷键

@gemini-code-assist gemini-code-assist Bot left a comment

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.

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.

Comment on lines +121 to +142
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)
})
}

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.

medium

waitForModifierKeysReleased 方法中,wrappedResolvesetTimeout 的回调函数中被引用,但它的声明(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  }

@lzx8589561 lzx8589561 merged commit c3088ca into ZToolsCenter:main Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants