Skip to content

feat(tab-bar): 终端 Tab 支持双击内联重命名 - #209

Open
LiarCoder wants to merge 8 commits into
omdsh-dev:mainfrom
LiarCoder:feat/tab-rename
Open

feat(tab-bar): 终端 Tab 支持双击内联重命名#209
LiarCoder wants to merge 8 commits into
omdsh-dev:mainfrom
LiarCoder:feat/tab-rename

Conversation

@LiarCoder

@LiarCoder LiarCoder commented Aug 18, 2026

Copy link
Copy Markdown

feat(tab-bar): 终端 Tab 支持双击内联重命名

背景

侧边栏的终端 Tab 创建后只能显示自动编号(「终端 1」「终端 2」…),没有任何改名的入口。在右侧栏 + 底部面板双工作台、分栏拆分的场景下开多个终端时,只能靠编号区分用途——「这个是 dev server、那个连的是生产环境」这类信息没法写进标签。状态层其实早有 patchTab(state, tabId, { title }) reducer(浏览器 Tab 就用它持久化当前页面标题),缺的只是 tab 栏的重命名 UI 与接线。

实现效果

dsh-better-sidebar-终端标签支持重命名
  • 双击终端 Tab 的标签进入内联编辑,自动聚焦并全选当前名字(可直接打字覆盖);
  • Enter / 失焦提交Esc 取消,清空文本不提交;
  • 输入过程中不重置选区(修复了一个初版实现「每敲一个字符就全选、后字覆盖前字」的 ref 回调 bug,见回归测试);
  • IME 安全:中文输入法组词期间的 Enter 不会误提交;
  • 重命名经 patchTab 持久化到会话布局,刷新 / 切换会话后保留
  • 仅终端 Tab 可重命名:编辑器标签跟随文件路径、浏览器标签跟随页面标题,刻意保持不可改;
  • 双工作台(右侧栏 + 底部面板)的终端 Tab 都支持。

实现

  • TabBar.tsx:新增 canRenameTab / onRename props;双击标签进入编辑,渲染内联 <input>useCallback 稳定 ref,只在挂载时 focus + select);
  • split-pane.tsxWorkbenchActions 新增 renameTabcanRenameTab 沿 Workbench → NodeView → LeafView 透传;
  • Sidebar.tsxrenameTabstore.reduce(s => patchTab(s, tabId, { title }))canRenameTab 限定 tab.type === 'terminal'
  • locales.ts:新增 renameTab / renameTabHint(zh / en);
  • sidebar.module.css:新增 .tabRename 输入框样式(--dsw-alias-* 令牌驱动,跟随皮肤);
  • tests/tabbar-rename.spec.tsx:vitest + jsdom 回归测试(4 例)——逐字符输入累积且不重置选区、Enter 提交且不重复触发、Esc 取消 / 失焦提交、IME 组词 Enter 忽略。

验证

  • tsc --noEmit
  • pnpm build(tsc 声明 + tsdown 全部产物)✅
  • vitest run:613 passed / 8 failed / 3 skipped——8 个失败与本次改动无关,已 stash 改动后在纯净 main 上对比验证同样复现(本机 Windows 环境的既有问题)

双击终端 Tab 标签进入内联编辑(自动聚焦全选),Enter/失焦提交、
Esc 取消、空文本不提交;输入期间不重置选区(IME 安全)。重命名经
patchTab 随会话布局持久化。仅终端 Tab 可重命名(编辑器标签跟随
文件路径、浏览器标签跟随页面标题)。附 vitest+jsdom 回归测试。
havoc-rao pushed a commit to havoc-rao/DSH-better-sidebar that referenced this pull request Aug 20, 2026
Merge terminal-tab inline rename from omdsh-dev#209
(authored by LiarCoder) into this fork's modernized tab strip:

- Double-click a terminal tab's label to rename it inline (Enter/blur
  commits, Esc cancels, IME-aware); the new name persists with the layout.
- Grafted onto the fork's refactored tab strip (renderTabEl +
  workspace-bound pinned stubs) and the VSCode/Side-Bar layout: wired
  canRenameTab/onRename through the Workbench -> NodeView -> LeafView ->
  TabBar chain in both the right and bottom panel workbenches.
- Adds tests/tabbar-rename.spec.tsx and the renameTab/renameTabHint i18n
  keys.

Conflicts in Sidebar.tsx / TabBar.tsx / split-pane.tsx resolved by keeping
both the fork's workspace-window + VSCode-layout changes and the PR's
rename feature.
@HuanLinOTO HuanLinOTO added enhancement New feature or request P3 低:体验/建议 area/terminal Terminal tabs, PTY, font fallback labels Aug 23, 2026
…aderDesc i18n 全语言同步),解决 20 个语言文件冲突(双方 key 都保留)
…ev#541),解决 Sidebar.tsx 冲突(保留 patchTab 等 4 个仍在用的符号)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/terminal Terminal tabs, PTY, font fallback enhancement New feature or request P3 低:体验/建议

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants