Skip to content

[4685] 新增 Ctrl+Shift+[ / ] 切换标签页快捷键(macOS 为 Cmd+Shift+[ / ]) - #4702

Open
bnspopi wants to merge 1 commit into
MoganLab:mainfrom
bnspopi:bnspopi/200_27/tab_switch_hotkeys
Open

bnspopi wants to merge 1 commit into
MoganLab:mainfrom
bnspopi:bnspopi/200_27/tab_switch_hotkeys

Conversation

@bnspopi

@bnspopi bnspopi commented Oct 11, 2026

Copy link
Copy Markdown

需求

Closes #4685。新增快捷键在标签页之间快速切换:

平台 上一个 tab 下一个 tab
Windows / Linux Ctrl+Shift+[ Ctrl+Shift+]
macOS Cmd+Shift+[ Cmd+Shift+]

两端回绕:最后一个 tab 按「下一个」回到第一个,反之亦然。

改动

TeXmacs/progs/texmacs/texmacs/tm-files.scm

  • cyclic-view-index idx delta len:环形下标纯函数。len <= 0 返回 #f;单 tab 时原地不动。抽成纯函数是为了 headless 可测。
  • switch-to-view-offset delta:用 (tabpage-list #t) 取当前窗口 tab 序列,list-index 定位 (current-view),再交给已有的 switch-to-view-index 做实际切换(与 std 1…std 6 同一路径,不另起切换逻辑)。当前 view 不在本窗口 tab 列表或只有一个 tab 时不动作。
  • switch-to-next-view / switch-to-previous-view:偏移 ±1 的薄封装,供快捷键绑定。

TeXmacs/progs/generic/generic-kbd.scm

在 (kbd-map (:profile std) ...) 中、紧随 std 1…std 6 之后新增绑定。

关于为什么绑了三种写法:qt_utilities.cpp 的 from_key_press_event 对带 Shift 的可打印键按平台归一:

  • Windows / Linux:C-S- + Qt 上报的 { → C-{
  • macOS:M-S- + 非字母键 → M-S-<key>,而 Qt 在 macOS 上对 Shift+[ 上报的 key 可能是 [ 或 {(源码中已有 "M-+ for Qt 6.5 on macOS is M-S-=" 的同类注记)

因此分别绑 std { / std }(Windows/Linux)、std S-[ / std S-] 与 std S-{ / std S-}(macOS 两种可能)。std 前缀按平台展开为 C- / M-,多余的组合在对方平台上不会被触发,无副作用。全仓库 grep 确认 C-{、C-}、M-S-[、M-S-] 此前均未被绑定,无冲突。

TeXmacs/progs/texmacs/texmacs/tm-files-test.scm

补充两组 headless 测试(xmake r tm-files-test):

  • cyclic-view-index 前后回绕、单 tab 原地、空列表 #f;
  • switch-to-next-view 后 switch-to-previous-view,current-view 必须回到原值且不抛错(不依赖 headless 下的 tab 数量)。

未做的事

  • 没有加菜单项。issue 只要求快捷键;若希望在「视图」菜单里可见,可以后续补。
  • 本机没有 xmake / gf 构建环境,未能本地运行 xmake r tm-files-test 与 gf fmt,烦请以 CI 为准。改动全部在 Scheme 层,无 C++ 变更。
  • macOS 的实际按键归一形式无法在本机验证,故按源码分析绑了两种可能;若 CI/维护者在 mac 上确认只需一种,可删掉另一对。

🤖 Generated with Claude Code

tm-files.scm 新增:
- cyclic-view-index:环形下标纯函数,单 tab 时原地、空列表返回 #f;
- switch-to-view-offset / switch-to-next-view / switch-to-previous-view:
  基于 (tabpage-list #t) 与 (current-view) 定位当前 tab,按偏移回绕切换,
  复用已有的 switch-to-view-index 做实际切换。当前 view 不在本窗口 tab
  列表或只有一个 tab 时不动作。

generic-kbd.scm 的 std profile 绑定快捷键。Qt 对 Shift+[ 上报的 key 随平台
而异,qt_utilities.cpp 归一为三种形式(Windows/Linux "C-{";macOS "M-S-["
或 "M-S-{"),三种写法都绑以保证各平台一致。

tm-files-test.scm 补充 headless 测试:cyclic-view-index 的前后回绕与边界,
以及 next/previous 往返后 current-view 不变。

Closes MoganLab#4685

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Add hotkeys "Ctrl + Shift + [" and "Ctrl + Shift + ]" for switching through tabs

1 participant