Skip to content

feat: 预览标签页支持鼠标中键关闭 - #30

Merged
shaohaozhi286 merged 1 commit into
masterfrom
feat/middle-click-close-preview-tab
Aug 31, 2026
Merged

feat: 预览标签页支持鼠标中键关闭#30
shaohaozhi286 merged 1 commit into
masterfrom
feat/middle-click-close-preview-tab

Conversation

@LIUXIN557

Copy link
Copy Markdown
Collaborator

摘要

在工作区预览面板的标签条(文档 / 浏览器 / 会话变更 / git 变更)上,支持鼠标中键按下即关闭对应标签页,对齐 Chrome、VS Code 的默认行为。

实现要点

改动集中在 web/src/components/PreviewDetailsPanel.jsx

  • 关闭触发:tab <button> 新增 onAuxClickbutton === 1)→ 复用现有 onCloseTabclosePreviewrequestPreviewClose 链路。因此未保存草稿的确认弹窗免费继承,与 ✕ 按钮、右键菜单走同一条路径,未重写任何关闭逻辑。
  • autoscroll 抑制handleTabMouseDownbutton === 1 仅做 preventDefault() 挡掉浏览器中键自动滚动光标后早返回,不在此关闭;关闭交给独立的 auxclick 事件,与现有左键拖拽重排 / 激活逻辑完全隔离。
  • 开关:不加设置开关,默认开启(匹配编辑器 / 终端默认行为)。

决策背景

经澄清,相较 mousedown 方案选择 auxclick(按键抬起后派发,语义更标准,且不与拖拽启动逻辑在同一事件竞争分支)。macOS 触控板无中键,仅实体鼠标生效。

验证

  • 新增源码正则回归断言 web/src/lib/previewWorkbenchArchitecture.test.jsonAuxClick 路由到 onCloseTab,且 mousedown 中键分支只抑制 autoscroll 不关闭。已通过。
  • SPEC 文档:docs/superpowers/specs/2026-08-31-close-preview-tab-on-middle-click-design.md

已知边界

  • 中键正好按在 ✕ 关闭按钮上时也会关闭该 tab(auxclick 不被 ✕ 的 mousedown stopPropagation 拦截,结果一致,可接受)。
  • macOS 触控板无中键,仅实体鼠标有效。

🤖 Generated with WorkBuddy

Add middle-mouse-button (button===1) close support to preview panel tabs
(file/browser/session-changes/git-changes), aligning with Chrome and VS Code
behavior. Closing reuses the existing onCloseTab -> closePreview ->
requestPreviewClose path, so unsaved-draft confirmation is inherited for free.

Two changes in PreviewDetailsPanel.jsx:
- handleTabMouseDown: middle button now calls preventDefault() to suppress the
  browser autoscroll cursor, then returns early (does NOT close here).
- tab <button>: new onAuxClick handler routes middle-click to onCloseTab.

Using auxclick (fires on button release) instead of mousedown keeps the close
trigger isolated from the existing mousedown/pointerdown drag-reorder logic.

No preference toggle added; the feature is always on (matches editor/terminal
defaults). macOS trackpads have no middle button, so this only affects physical
mice.

Includes source-regex regression test in previewWorkbenchArchitecture.test.js
and a SPEC doc at docs/superpowers/specs/.

@shaohaozhi286 shaohaozhi286 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

批准合入。

中键关闭走 auxclick + onCloseTab,能复用未保存确认。handleTabMouseDownbutton === 1preventDefault 不关 tab;handleTabPointerDown 本来就只处理左键,不会跟拖拽冲突。源码正则回归覆盖了这条路径。

@shaohaozhi286
shaohaozhi286 merged commit ffa3455 into master Aug 31, 2026
1 check passed
@shaohaozhi286
shaohaozhi286 deleted the feat/middle-click-close-preview-tab branch August 31, 2026 17:21
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