Skip to content

fix: prevent terminal close on custom command deletion - #590

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/agent/d8eba252a890
Nov 11, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/agent/d8eba252a890

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

When editing a custom command and pressing Tab+Enter to trigger the delete button, ListView::onCustomCommandOptDlgFinished calls Service::instance()->setIsDialogShow(window(), false) unconditionally at the end of the function. This re-enables the main window and restores focus to the terminal while the delete confirmation DDialog (shown via non-blocking show()) is still visible. The residual Enter key event then leaks to the terminal, gets sent as \n to the shell, and can cause the shell to exit, closing the terminal window.

Key evidence: src/views/listview.cpp:631 (unconditional setIsDialogShow(false)) + src/views/listview.cpp:596 (dlgDelete->show() non-blocking). Demo verification confirmed Enter reaches terminal in buggy version (Terminal received Enter: 1) and is blocked in fixed version (Terminal received Enter: 0).

Fix

Guard the setIsDialogShow(window(), false) call in onCustomCommandOptDlgFinished with a condition that skips it when result == Rejected and m_pdlg->isDelCurCommand() is true (delete confirmation dialog showing). Add setIsDialogShow(window(), false) at the end of onDeleteCustomCommandFinished to restore window state after the confirmation dialog closes. All other paths (Accepted, Rejected without delete) keep the original call unchanged.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target line is not a historical bug fix product; this change does not revert any prior fix
  • No function signature changes, no public API changes; only 2 callers identified (unit test + header declaration), both compatible

Business Impact Scope

Affects only the custom command delete-confirmation interaction path. Editing (Accepted) and canceling (Rejected without delete) paths keep original behavior. Users can now delete custom commands via Tab+Enter without the terminal window closing unexpectedly.

Verification Suggestion

Regression test all three paths: save custom command edit, cancel edit, and delete command via Tab+Enter — verify terminal stays open during delete confirmation and window state restores after confirmation dialog closes.


根因分析

编辑自定义命令时通过 Tab+Enter 触发删除按钮,ListView::onCustomCommandOptDlgFinished 在函数末尾无条件调用 setIsDialogShow(window(), false),在删除确认 DDialog(非阻塞 show() 显示)仍可见时重新启用主窗口并恢复终端焦点。残余的 Enter 键事件泄漏到终端,被当作 \n 发送给 shell,导致 shell 退出、终端窗口关闭。

关键证据:src/views/listview.cpp:631(无条件 setIsDialogShow(false))+ src/views/listview.cpp:596(dlgDelete->show() 非阻塞)。Demo 验证确认 BUGGY 版本 Enter 到达终端(Terminal received Enter: 1),FIXED 版本 Enter 被阻断(Terminal received Enter: 0)。

修复方案

在 onCustomCommandOptDlgFinished 中条件化 setIsDialogShow(window(), false) 调用,当 result == Rejected 且 isDelCurCommand() 为 true(删除确认对话框显示中)时跳过。在 onDeleteCustomCommandFinished 末尾补充调用 setIsDialogShow(window(), false),确保确认对话框关闭后恢复主窗口状态。其余路径(Accepted、Rejected 无删除)保持原有调用不变。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标行非历史修复产物,本次改动不撤销任何已有修复
  • 无函数签名变更、无公开接口变更;仅 2 个调用者(单元测试 + 头文件声明),均兼容

业务影响范围

仅影响自定义命令删除确认交互路径。编辑保存(Accepted)和取消编辑(Rejected 无删除)路径保持原有行为。用户通过 Tab+Enter 删除自定义命令时终端窗口不再意外关闭。

验证建议

回归测试三条路径:保存自定义命令编辑、取消编辑、通过 Tab+Enter 删除命令 — 验证删除确认期间终端不关闭,确认对话框关闭后窗口状态恢复。

Summary by Sourcery

Keep the main window blocked while custom command deletion is being confirmed, then restore it after the confirmation completes.

Bug Fixes:

  • Prevent the terminal from receiving residual Enter events and closing unexpectedly when deleting a custom command via Tab+Enter.
  • Restore the main window state after the custom command deletion confirmation dialog closes.

1. Root cause: onCustomCommandOptDlgFinished called
   setIsDialogShow(window(), false) unconditionally at function end,
   re-enabling the main window while the delete confirmation DDialog
   was still shown via non-blocking show(), allowing Enter key events
   to leak to the terminal and trigger shell exit
2. Fix: guard the setIsDialogShow(false) call with a condition that
   skips it when result is Rejected and a delete confirmation dialog
   is showing; add setIsDialogShow(false) at the end of
   onDeleteCustomCommandFinished to restore window state after the
   confirmation dialog closes
3. Impact: only the delete-confirmation path of custom command editing
   is affected; Accepted and plain Rejected paths keep original behavior

Log: fix terminal window closing when deleting custom command via Tab+Enter

Influence:
1. Test editing a custom command and saving — window state restores normally
2. Test canceling custom command edit — window state restores normally
3. Test deleting custom command via Tab+Enter — terminal window stays open
4. Test delete confirmation dialog dismiss — window state restores after

fix: 修复删除自定义命令时终端窗口关闭的问题

1. 根因:onCustomCommandOptDlgFinished 在函数末尾无条件调用
   setIsDialogShow(window(), false),在删除确认 DDialog 以非阻塞
   show() 显示时重新启用主窗口,导致 Enter 键事件泄漏到终端触发
   shell 退出
2. 方案:条件化 setIsDialogShow(false) 调用,在 Rejected 且有删除
   确认对话框时跳过;在 onDeleteCustomCommandFinished 末尾补充调用
   setIsDialogShow(false),确保确认对话框关闭后恢复主窗口状态
3. 影响:仅影响自定义命令编辑的删除确认路径,Accepted 和普通
   Rejected 路径保持原有行为

Log: 修复通过 Tab+Enter 删除自定义命令时终端窗口关闭的问题

Influence:
1. 测试编辑自定义命令并保存 — 窗口状态恢复正常
2. 测试取消自定义命令编辑 — 窗口状态恢复正常
3. 测试通过 Tab+Enter 删除自定义命令 — 终端窗口不再关闭
4. 测试删除确认对话框关闭 — 确认后窗口状态恢复

PMS: BUG-381129
@pengfeixx
pengfeixx marked this pull request as draft November 6, 2026 21:53
@sourcery-ai

sourcery-ai Bot commented Nov 6, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Keep the main window disabled while the delete confirmation is open, then restore its state when that dialog finishes.

  • src/views/listview.cpp L631-634, L700-702

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@pengfeixx
pengfeixx marked this pull request as ready for review November 11, 2026 06:37
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pengfeixx

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit ab675d8 into linuxdeepin:master Nov 11, 2026
13 checks passed
@pengfeixx
pengfeixx deleted the agent/agent/d8eba252a890 branch November 11, 2026 06:38
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.

3 participants