Skip to content

feat(tabs): 补上 Close to the Left,⌘⌥W 关掉其他标签页 - #239

Merged
oratis merged 2 commits into
mainfrom
feat/tabs-close-left-shortcut
Aug 24, 2026
Merged

feat(tabs): 补上 Close to the Left,⌘⌥W 关掉其他标签页#239
oratis merged 2 commits into
mainfrom
feat/tabs-close-left-shortcut

Conversation

@oratis

@oratis oratis commented Aug 23, 2026

Copy link
Copy Markdown
Owner

三个叠放 PR 里的 第 2 个,基于 #238(先合那个)。设计:docs/design/10-close-many-tabs.md §1.4、§4.6。

Summary

  • Close to the Left:有右没左——看长文顺着 wikilink 一路点进去,最后停在最右边,想关掉左边那一串,没这个动词。closeTabsToRight 和新的 closeTabsToLeft 收口成 closeSide(),固定页照旧不动,轴心页留下并在激活页被关掉时接管。
  • ⌘⌥W = Close Other Tabs:键盘上原本一条关闭类命令都没有(唯一的 ⌘W 烧在原生菜单里,不能改键、不进速查表)。走 shortcuts.ts,所以可改键、出现在 ⌘⇧/ 速查表和设置的快捷键编辑器。
  • 命令面板补 Close Other Tabs / Close Tabs to the Left / Close Tabs to the Right(原来只有 Close All Tabs 一条)。
  • Review 后补的(第 2 个提交):
    • eventToShortcut 只看 e.key,而 macOS 的 Option 层会先把字母合成成符号(⌥W → ,⌥] → ,⌥E → 死键),所以 Mod+Alt+* 这一整类绑定——包括既有的 ⌘⌥S / ⌘⌥T / ⌘⌥B / ⌘⌥] / ⌘⌥[——在 macOS 上可能从来没匹配上过。修法:Alt 按下且 e.key 是合成字符时改从 e.code 取键名;纯 ASCII 的 Alt 组合不动,AltGr 布局照旧打字。
    • 右键菜单的 Close Others / to the Left / to the Right / All 按"是否真有非固定页会被关"置灰——固定页永远排最前,"左边全是固定页"是常态不是边角。

⚠️ 请你真机按一下 ⌘⌥T

我没能在真机上验证 Option 合成的行为(这轮没有授权驱动应用),上面那条修补是按合成事件的单元测试写的(∑/KeyW、‘/BracketRight、†/KeyT、Dead/KeyE → 预期绑定;@/KeyQ 保持原样)。在现有的 1.0.1 里按一次 ⌘⌥T:能切主题 → 老绑定本来就好,补丁是惰性的;不能切 → review 说对了,补丁顺手把五个老绑定也救活。两种结果都不需要改代码,但值得知道。

How to verify

pnpm install
pnpm tauri:dev
  1. 开四个文件,右键第三个 → Close to the Left → 只剩第三、四个;右键第一个,该项是灰的;固定第一个再右键第二个,该项也是灰的(左边没有能关的)。
  2. 开几个,按 ⌘⌥W → 只剩当前页(固定页除外)。
  3. ⌘⇧/ 速查表里能看到 Close Other Tabs;设置 → Shortcuts 里能改它。
  4. ⌘⇧P 输 "close" → 四条关闭命令。

Checks

  • pnpm tsc --noEmit clean
  • pnpm lint clean
  • pnpm test --run green(1033,本 PR +12)
  • cd src-tauri && cargo test — 未动 Rust
  • Tested manually on macOS(dev server smoke)
  • Performance budget unchanged
  • No new dependencies added

Notes for the reviewer

  • ⌘⌥W 选它是因为它是 ⌘W 的近邻、本机菜单没占、不撞任何现有绑定(menu.rs 的 accelerator 里没有 Alt+W),也是 Safari 自己的 Close Other Tabs。
  • 没做「Close Saved」——设计辩题四:autosave 默认开着,它永远等价于 Close Others,是菜单噪音。
  • 合并后 feat(tabs): 标签页多选——⌘点挑、⇧点连选,⌘W 关掉选中的一批 #240 需要 git rebase --onto main feat/tabs-close-left-shortcut feat/tabs-multi-selectpush -f;我会跟。

🤖 Generated with Claude Code

@oratis oratis left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review

  • closeSide 合并左右两个方向顺手消灭了 closeTabsToRight 的重复实现,轴心接管激活页的规则两侧一致。
  • ⌥ 组合按物理键匹配是本 PR 真正的难点,处理是对的:只在「Alt 按下 + key 是合成产物(非 ASCII 或 Dead)」时才退回 e.code,纯 ASCII 一律不动——注释点名了 AltGr 布局靠 Ctrl+Alt 打字这条底线,测试三个方向都覆盖(∑、dead key、ASCII 放行)。
  • 一个知道即可的残余风险(不改):Windows 上若某布局的 AltGr+W 产出非 ASCII 字符,会被映射成 Mod+Alt+W 从而触发 Close Others 而不是打字。主流布局的 AltGr+W 要么无输出要么是 ASCII(|),且 Windows 端还没发布——真到跨平台发布时再加平台判断也来得及。
  • 菜单置灰语义升级为"这一侧没有会被真正关掉的"(而不是"这一侧没有标签页"),和 pinned 契约对齐,三条 close 项一致。
  • ⌘⌥W 进 shortcuts.ts 而非烧死在原生菜单,自动出现在速查表和改键编辑器——符合设计 §4.6 选它的理由。

没有要改的。

@oratis
oratis deleted the branch main August 24, 2026 04:15
@oratis oratis closed this Aug 24, 2026
@oratis oratis reopened this Aug 24, 2026
@oratis
oratis changed the base branch from fix/tabs-bulk-close-confirm to main August 24, 2026 04:16
oratis and others added 2 commits August 24, 2026 12:17
有「Close to the Right」没有「Close to the Left」:看长文顺着 wikilink
一路点进去,最后停在最右边,想关掉左边那一串——没有这个动词。
closeTabsToRight 和新的 closeTabsToLeft 收口成一个 closeSide(),
固定页照旧不动,轴心页留下并在激活页被关掉时接管。

键盘上原本一条关闭类命令都没有(唯一的 ⌘W 烧在原生菜单里,不能改键、
不进速查表)。加 Close Other Tabs = ⌘⌥W,走 shortcuts.ts,所以可改键、
出现在 ⌘⇧/ 速查表和设置里的快捷键编辑器。其余批量动作只上命令面板 +
右键菜单:它们要么天然需要一个轴心,要么本来就是指针场景,占全局键位
不划算。见 docs/design/10-close-many-tabs.md §4.6。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
review 指出:eventToShortcut 只看 e.key,而 macOS 的 Option 层会先把
字母合成成符号(⌥W → "∑",⌥] → "‘",⌥E → 死键),于是 "Mod+Alt+W"
这类绑定在 macOS 上可能永远匹配不上。这不是本 PR 新引入的——既有的
⌘⌥S / ⌘⌥T / ⌘⌥B / ⌘⌥] / ⌘⌥[ 走的是同一条路,仓库里没有任何测试或
e2e 用真实的合成字符验过它们。

修法:Alt 按下且 e.key 是合成字符(非 ASCII 或 "Dead")时,键名改从
e.code 取(KeyW → W,BracketRight → ],…)。纯 ASCII 的 Alt 组合不动,
AltGr 布局(德语 Ctrl+Alt+Q = @)照旧打字。

没能在真机上验证合成行为(本机未授权驱动应用),所以用合成事件写了
单元测试:∑/KeyW、‘/BracketRight、†/KeyT、Dead/KeyE 都落到预期绑定,
@/KeyQ 保持原样。如果真机上 ⌘⌥T 本来就能切主题,这条补丁是惰性的。

另:右键菜单里 Close Others / Close to the Left / Right / All 按"是否
真有非固定页会被关"来置灰,而不是按"那一侧有没有标签页"——固定页永远
排在最前,"左边全是固定页"是常态不是边角。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@oratis
oratis force-pushed the feat/tabs-close-left-shortcut branch from 26ca8fc to 8cec189 Compare August 24, 2026 04:17
@oratis
oratis merged commit 8da4a13 into main Aug 24, 2026
6 checks passed
@oratis
oratis deleted the feat/tabs-close-left-shortcut branch August 24, 2026 04:26
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