Skip to content

feat:支持禁用 ESC。插件内弹窗很多都是 ESC 来关闭的,退出插件可以用 Cmd + W/Q #332#556

Open
cjhgit wants to merge 1 commit into
ZToolsCenter:mainfrom
yunser:feature/esc-shortcut-disable
Open

feat:支持禁用 ESC。插件内弹窗很多都是 ESC 来关闭的,退出插件可以用 Cmd + W/Q #332#556
cjhgit wants to merge 1 commit into
ZToolsCenter:mainfrom
yunser:feature/esc-shortcut-disable

Conversation

@cjhgit

@cjhgit cjhgit commented Jun 20, 2026

Copy link
Copy Markdown
Member

No description provided.

@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 configurable 'esc' built-in shortcut key, updating the settings UI, main process API, renderer keydown handler, and window store to support enabling or disabling it. A critical issue was identified in the renderer's keydown handler where an asynchronous await database call is executed before event.preventDefault(), which prevents the default behavior from being successfully blocked. It is recommended to use the synchronous windowStore.builtInEscShortcutEnabled state instead.

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 thread src/renderer/src/App.vue Outdated
Comment on lines +476 to +480
const settings = (await window.ztools.dbGet('settings-general')) || {}
const isEnabled = settings?.builtinAppShortcutsEnabled?.esc !== false
if (!isEnabled) {
return
}

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.

high

在 JavaScript/TypeScript 的事件处理函数中,event.preventDefault() 必须在事件的同步执行流中调用。如果在调用 event.preventDefault() 之前使用了 await(即进行了异步等待),那么在 Promise 解析并执行后续代码时,浏览器/Electron 的默认事件行为已经发生,此时再调用 event.preventDefault() 将完全失效。

为了解决这个问题,建议直接使用已经加载到 windowStore 中的 builtInEscShortcutEnabled 进行同步判断,这样可以确保 event.preventDefault() 能够正常工作并阻止默认行为。

    if (!windowStore.builtInEscShortcutEnabled) {
      return
    }

@cjhgit cjhgit force-pushed the feature/esc-shortcut-disable branch from 38c833e to 2593e66 Compare June 20, 2026 10:34
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.

1 participant