Repository navigation
fix(schedule): AI 定时任务模型下拉打开时按 Esc 不再关掉整个编辑器 - #1505
Robert0622 wants to merge 2 commits into
Conversation
Pressing Esc while the model menu of the AI schedule editor was open closed the menu and the editor in one keystroke, discarding the unsaved draft. The menu now handles Esc in the capture phase, closes itself, returns focus to the model button and stops the page-level handler; a second Esc still closes the editor. Co-Authored-By: Claude Code <noreply@anthropic.com>
…yers' Esc - Close the model menu together with the editor. A menu left open when the editor closes without a click (save, failed load, project switch) kept the capture-phase handler armed, so the next Esc on another modal only closed the hidden menu. - Skip the handler while a confirm dialog or the command palette sits above the editor. The confirm binds its capture handler lazily, after the model picker, so stopImmediatePropagation kept the confirm open and moved focus behind it. Co-Authored-By: Claude Code <noreply@anthropic.com>
CR + 部署实测:a5cc7537 → f397e98 ✅ 可以合入结论:修复正确。模型下拉打开时,第一次 Esc 只关下拉,编辑器和草稿都保留,焦点回到「模型」按钮;第二次 Esc 才关编辑器。f397e987 补上了 a5cc753 的两处边界情况,实测确认都修好了,其他 Esc 行为没有回归。 代码
部署实测(本机 MariaDB 11.8.9;main fd039e5、a5cc7537、f397e987 三套构建共用一个库;Chromium + Playwright)
测试
说明:评审用的 GitHub 凭据就是作者本人,没法提交正式 Approve,还需要一位非作者评审人点 Approve。 |
23:00 轮补充修复:
|
| # | 现象 | 原因 | 修复 |
|---|---|---|---|
| 1 | 编辑器不经点击被关掉(保存成功、加载失败、切项目)后,下拉仍开着;之后在任何别的弹窗按第一下 Esc 只关掉这个看不见的下拉,弹窗不关 | closeScheduleJobModal() 不关下拉,捕获处理器一直处于「有下拉」状态并先截走 Esc |
closeScheduleJobModal() 里先 closeScheduleModelMenu() |
| 2 | 下拉打开时弹出确认框(例如切换项目前的未保存确认),第一下 Esc 确认框不关,焦点跑到确认框后面的「模型」按钮 | 确认框的捕获处理是首次弹出时才懒绑定,排在模型下拉之后,被 stopImmediatePropagation() 挡掉 |
Esc 处理器在 #confirmModal 打开时直接返回 |
| 3 | 下拉打开时 Ctrl/⌘K 打开命令面板,第一下 Esc 面板不关,焦点跑到面板后面 | 同上,命令面板的 Esc 处理在冒泡阶段之外被别人抢先 | Esc 处理器在 #commandPalette 可见时或 e.defaultPrevented 时返回 |
原修复行为不变:第一下 Esc 只关下拉并把焦点还给「模型」按钮,草稿保留;第二下才关编辑器。
部署实测(本机 MariaDB + Chromium,main / a5cc7537 / f397e987 三套构建)
| 场景 | main |
a5cc7537 |
f397e987 |
|---|---|---|---|
| 下拉打开按 Esc:编辑器与草稿 | 编辑器被关 ❌ | 保留 ✅ | 保留 ✅ |
| 第二下 Esc 关编辑器 | — | ✅ | ✅ |
| 点输入框关闭下拉、下拉选项可正常选择 | ✅ | ✅ | ✅ |
| 编辑器被关后,其他弹窗第一下 Esc | 关 ✅ | 不关 ❌ | 关 ✅ |
| 下拉打开时确认框第一下 Esc | 确认框关 ✅(下拉也会跟着关) | 只关下拉 ❌ | 确认框关、编辑器与下拉保留 ✅ |
| 下拉打开时命令面板第一下 Esc | 面板关 ✅ | 只关下拉 ❌ | 面板关 ✅ |
选 deepseek-v4.1-flash → 保存并立即执行(真实 CodeBuddy) |
— | — | 成功,回复入库 ✅ |
新增 2 个 webtest 用例(在 a5cc7537 上失败、在 f397e987 上通过):
closing the AI job editor with the model menu open does not swallow the next Escapea confirm dialog or the command palette above the AI job editor keeps its Escape while the model menu is open
npm --prefix webtest run coverage:398/398 通过,行覆盖率 85.21%。
crispinhu27
left a comment
There was a problem hiding this comment.
初审,当前 head 是 f397e987f071adaeeb3c108b5e22a8a330aa55ab,base main fd039e51。审查过程中 head 从 a5cc7537 更新到 f397e987,以下结论都在 f397e987 上重新验证过。
审查范围:web/app/sync-schedule.js 里模型下拉的捕获阶段 Esc 处理,closeScheduleJobModal() 关闭时会同时关掉下拉;以及 webtest/tests/sync-schedule.test.mjs 新增的用例。
验证(无凭据隔离用户,合成数据,jsdom 加载真实的 app 代码)
- 在
a5cc7537上复现了两个 main 上没有的回归:① 模型下拉打开时用 Ctrl/⌘+K 打开命令面板,第一次 Esc 会被下拉截走,面板关不掉,焦点被移走;② 保存过程中打开下拉,编辑器关闭后下拉状态没有复位,之后页面上第一次 Esc 被吞掉并preventDefault。同一份复现脚本在f397e987上 2/2 通过,两个问题都已修复,所以没有作为行内问题发布。 f397e987上:sync-schedule.test.mjs24/24 通过,全量 webtest 398/398 通过。新增的「下拉打开时 Esc 只关下拉」用例放到 main 上会失败。连按两次 Esc 先关下拉、再关编辑器,符合预期。- 当前 head 上 CI 16/16 全部通过。
非阻塞说明:@ 资产选择器的 Esc 由 composer 上的 React onKeyDown 处理,触发要先用键盘从打开的下拉 Tab 进提示词,再输入 @。这时 Esc 仍会先关模型下拉,但 main 上同样的操作会直接关掉整个编辑器,所以不算本 PR 引入的回归。这条没有在真实浏览器里实测。
本结论只针对上述审查范围,不代表代码没有其他缺陷。









概要
2026-11-27 20:00 全量走查(main
fd039e51,本机真实部署 + 真实 LLM + 私有测试库)在深测 #1440 的 AI 定时任务编辑器时发现:模型下拉打开时按一次 Esc,下拉和整个「AI 定时任务」编辑弹窗会一起关掉,任务名和提示词等未保存的草稿全部丢失。原因
bindScheduleModelPicker()在document上挂了冒泡阶段的 keydown,按 Esc 时只关下拉。app.js的全局 Esc 处理也挂在document上,而且注册得更早,会先执行。它发现#scheduleModal是打开的,就直接调用closeScheduleJobModal()。影响:新建或编辑 AI 定时任务时,打开模型菜单后习惯性按 Esc 收起菜单,整个编辑弹窗被关掉,填好的名称、提示词、调度、通知配置全部丢失,需要重新填写。
复现(main
fd039e51,本机真实部署)modalOpen=false),草稿丢失。修复
web/app/sync-schedule.js:模型下拉的 Esc 处理改在捕获阶段注册,并且只在下拉打开时处理:preventDefault()加stopImmediatePropagation(),页面级的 Esc 处理不会再收到这次按键;新增 webtest 用例
Escape closes the AI job model menu first and keeps the editor and its draft open:在 main 上失败(the editor stays open断言),在本 PR 上通过。影响面:只改这一个下拉的 Esc 行为。点击外部、滚动、resize 关闭下拉的逻辑不变,选择模型的逻辑不变。
修复后(本 PR 构建部署后实测)
同样的操作,第一次 Esc 只关下拉,编辑弹窗和草稿都还在,焦点回到「模型」按钮;第二次 Esc 才关闭编辑弹窗。
回归(真实浏览器,修复后构建):
测试
node --test tests/sync-schedule.test.mjs:新增用例在 main 上失败,在本 PR 上通过。npm --prefix webtest run coverage:396/396 通过,行覆盖率 85.21%(门槛 85%)。🤖 Generated with Claude Code