diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aeafec..f1cc52b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,15 @@ > 倒序排列,新版本条目在最上面。条目格式:`## vX.Y.Z — YYYY-MM-DD` + 类型(feat / fix / docs / chore)+ 要点 + 相关链接。 > 纪律见 AGENTS.md「变更记录纪律」:发版前先更新本文件并随版本提交。 +## Unreleased + +**类型**:feat(输入框变化统计可点击,直接打开 Git 面板的差异) + +- **变化统计即「显示差异」**:输入框工具条 Git 胶囊里的 `±N` / `+N −N` 从纯展示改成按钮——点它就是一次「显示差异」:打开 Git 面板(有 dsh-better-sidebar 时用它的右栏 Git 页签,没有时走原生 `sidebarRight`),把面板切到该仓库并直接给出第一个未提交文件的差异(与左栏动作条的「显示差异」同一条接受路径)。胶囊与面板的仓库/分支联动沿用原有 store。 +- **跨座位交接**:胶囊在宿主输入框、面板在侧栏页签,是两个独立 React 树。点击把 `{ sessionId, repoRoot }` 停在模块级请求里并唤醒已挂载的面板;面板在自己的下一次可见窗口消费:仓库不同先用 `pickRepo` 搬过去,等该仓库的 summary 到位再跑 `showWorkingDiff()`。请求 10 秒未被消费即丢弃,不会在很久以后突然把面板弹出来;别的会话不会吃掉这条请求。 +- **没有右侧栏时**:按钮禁用,悬停说明「当前环境没有可用的右侧栏」(复用 `diff.sidebar.unavailable`),不装作可点。 +- **测试**:`npm test` 153/153(新增 reveal store 的会话隔离 / 一次性消费 / TTL 过期断言,以及按钮接线、`action.showDiff` tooltip、CSS 指针态与面板消费路径断言);`node --check src/client.js`。 + ## v0.33.0 — 2026-11-12 **类型**:chore(适配 dsh 0.2.2-rc.2 的复核) diff --git a/README.md b/README.md index ce263e4..16a92f3 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ DSH 自带的 Git 面板覆盖「暂存 / 提交 / 还原 / 看历史」;`dsh-id - **想比较分支**:分支右键即可与当前分支比较,结果按文件与提交数汇报。 - **操作要够全**:签出、从任意分支/提交新建分支、重命名、删除、合并到当前(默认 / `--no-ff` / `--squash` / `--no-ff --no-commit`)、变基当前到此、新建标签、cherry-pick、还原提交、重置(保留/丢弃)、fetch / pull --ff-only / push(确认后);留下待提交的合并后,可在「更多操作 → 提交 → 中止合并」退出。 - **卡住时知道卡在哪**:面板加载超过 2 秒会出现诊断条——分段进度(fetch / summary / stats / branches / log)、当前活动 git 子命令与已运行时长;宿主 2.5 秒不应答时提示「宿主无响应」,并可一键复制诊断 JSON。正常加载与后台轮询不显示诊断条。 -- **输入框里就能看 Git**:输入框工具条上有仓库与分支胶囊(着色的未提交 / 可拉取 / 待推送计数),点击弹出可搜索的切换器——仓库按名称/路径过滤,分支按 `/` 折成文件夹树(`fix/xxx` 一眼看清),输入即滤、方向键 + Enter 可选;多仓库工作区两边都能切,切换与面板实时联动,设置里可关(默认开);选择器里还有「打开其他仓库…」,输入绝对路径即可把工作区外的仓库加入并按会话记住。切到新会话也不用等——插件会在你点开会话时就预热首屏数据,面板秒开。 +- **输入框里就能看 Git**:输入框工具条上有仓库与分支胶囊(着色的未提交 / 可拉取 / 待推送计数),点击弹出可搜索的切换器——仓库按名称/路径过滤,分支按 `/` 折成文件夹树(`fix/xxx` 一眼看清),输入即滤、方向键 + Enter 可选;多仓库工作区两边都能切,切换与面板实时联动,设置里可关(默认开);**着色变化统计(±N / +N −N)本身就是「显示差异」的入口**:点它直接打开 Git 面板(右侧栏)并把第一个未提交文件的差异摆出来,没有可用右侧栏时按钮置灰并写明原因;选择器里还有「打开其他仓库…」,输入绝对路径即可把工作区外的仓库加入并按会话记住。切到新会话也不用等——插件会在你点开会话时就预热首屏数据,面板秒开。 ## 效果 @@ -100,7 +100,7 @@ DSH 自带的 Git 面板覆盖「暂存 / 提交 / 还原 / 看历史」;`dsh-id | 窄栏页签 | 宽度 < 600px 的两种纵向布局里:变更列表固定在上方,下方是「历史 / 差异」两个页签——点变更文件自动切到「差异」,历史列表与它的滚动位置都不再被顶走;两区之间的分隔条可拖动、双击复位(尺寸与 `dsh-ide-git.panes.v1` 其它面板同一份存储) | | 悬停提示 | 鼠标停在图标按钮上 120ms,指针旁弹出它的操作名——竖排动作条里在图标右侧(跟着该行垂直居中,贴窗口右缘时翻到左侧),其余在下方;置灰的动作连原因一起给出(如 `隐藏 · 当前状态不可用`)。提示卡挂在窗口层,底部工作台裁不到;扫过一排图标不闪,按住鼠标拖拽 / 滚动 / 缩放时立即收起 | | 状态行 | 当前分支、上游、`↑ahead ↓behind`、stash 数量、忙碌指示 | -| 输入框状态条 | 宿主输入框工具条里的仓库/分支胶囊(着色 ±未提交 / ↓可拉取 / ↑待推送),点击切换仓库与分支,与面板双向联动;单仓库默认只切分支,多仓库两边都切,手动入口可打开工作区外的仓库;设置可关(默认开) | +| 输入框状态条 | 宿主输入框工具条里的仓库/分支胶囊(着色 ±未提交 / ↓可拉取 / ↑待推送),点击切换仓库与分支,与面板双向联动;单仓库默认只切分支,多仓库两边都切,手动入口可打开工作区外的仓库;设置可关(默认开)。**着色变化统计(±N / +N −N)可点击**:点了就是「显示差异」——打开 Git 面板并直接落到第一个未提交文件的差异(与左栏动作条的「显示差异」同一条路径),没有可用右侧栏时置灰并说明原因 | | 仓库/分支切换器 | 面板顶部与输入框胶囊共用同一个可搜索选择器:仓库按名称、路径、克隆目录或当前分支过滤,并标出各仓当前分支;分支按 `/` 折成文件夹树,输入时自动展开命中的目录,方向键 + Enter 可选,过滤器为空时目录可手动折叠。列表底部可手动输入绝对路径打开工作区外的仓库,按会话记住最近 8 条 | | 分支树 | `HEAD / 本地 / 远程 / 标签` 分组(可折叠)、过滤框、星标当前分支、ahead/behind 角标、worktree 占用标记;本地蓝 / 远程紫 / 标签黄 / HEAD 绿 | | 工作树 | 动作条新增「工作树」视图:列出主工作树与全部链接工作树(当前 / 主工作树 / 已锁定 / 可清理标记、分支、短 HEAD、路径),可新建(新分支或挂已有分支,可指定起点)、在面板中打开、复制路径、移除(有未提交改动需二次强制确认)、清理失效记录;与官方「变更请求」面板并存 | diff --git a/README_EN.md b/README_EN.md index 74bd024..bad0c93 100644 --- a/README_EN.md +++ b/README_EN.md @@ -88,7 +88,7 @@ The panel never guesses: it measures itself with a `ResizeObserver` (width ≥ 6 - Hover hints: rest the pointer on an icon button for 120ms and its action name appears beside it — to the RIGHT of a vertical rail icon (centred on that row, flipping to the left when the window's right edge is in the way) and below everywhere else; greyed-out actions explain themselves too (e.g. `Hide · Not available in the current state`). The hint card lives on the window layer, so the bottom workbench cannot clip it — sweeping across a row of icons does not flash, and a pressed pointer / scroll / resize drops it immediately. - Status line: branch, upstream, ahead/behind, stash count, busy indicator. - Slow-load trace: if a panel load takes more than 2 seconds, a compact trace appears with per-phase progress (fetch / summary / stats / branches / log), the active git subcommand and its runtime, a "host not responding" state after 2.5 seconds, and one-click copy of a diagnostic JSON. Normal loads and background polling stay quiet. -- Composer status pill: repository/branch capsule in the host input-bar tool row (colored uncommitted / pullable / to-push counters), click to open a searchable switcher — repositories filter by name or path, branches fold on `/` into a folder tree (`fix/xxx` stays legible), typing filters immediately, arrow keys + Enter pick. Kept in sync with the panel both ways; single-repo workspaces switch branches only, multi-repo workspaces switch both, and the manual entry can open a repository outside the workspace. Off-switch in the settings (on by default). Sessions are pre-warmed on switch so the panel opens instantly. +- Composer status pill: repository/branch capsule in the host input-bar tool row (colored uncommitted / pullable / to-push counters), click to open a searchable switcher — repositories filter by name or path, branches fold on `/` into a folder tree (`fix/xxx` stays legible), typing filters immediately, arrow keys + Enter pick. Kept in sync with the panel both ways; single-repo workspaces switch branches only, multi-repo workspaces switch both, and the manual entry can open a repository outside the workspace. Off-switch in the settings (on by default). Sessions are pre-warmed on switch so the panel opens instantly. The colored change counters (`±N` / `+N −N`) are themselves a **Show diff** button: they open the Git panel in the right sidebar and land on the first uncommitted file's diff (the same accept the rail's Show diff runs), and grey out with a reason when no right sidebar exists. - Repo/branch switcher: the panel header and the composer pills share one searchable picker. Repositories filter by name, path, clone directory or current branch and show each clone's checked-out branch; branches fold on `/` into a folder tree that opens matching folders while typing, arrow keys + Enter pick, and folders stay collapsible on an empty filter. The list footer accepts an absolute path to open a repository outside the workspace and remembers the last 8 per session. - Branch tree: HEAD / Local / Remote / Tags groups, filter box, ahead/behind badges, worktree marker; local blue / remote violet / tag amber / HEAD green. - Worktrees: a rail view listing the primary and every linked worktree (current / primary / locked / prunable badges, branch, short HEAD, path). Create one on a new branch or attach an existing branch (with an optional start point), open it in the panel, copy its path, remove it (a dirty tree asks for a second, forced confirmation), and prune stale records. It coexists with the official change-request panel. diff --git a/src/client.js b/src/client.js index 02f04f1..69c785a 100644 --- a/src/client.js +++ b/src/client.js @@ -14814,6 +14814,10 @@ window.__ModuleLoader__.load({ phase starts or settles. */ const traceRef = useRef(null) const [traceTick, setTraceTick] = useState(0) + const [revealTick, setRevealTick] = useState(0) + const [revealPending, setRevealPending] = useState(0) + const revealRootRef = useRef(null) + const revealVisibleRef = useRef(props.visible === true) const cwd = typeof scope.cwd === 'string' && scope.cwd !== '' ? scope.cwd : undefined const sessionId = typeof scope.sessionId === 'string' ? scope.sessionId : 'default' @@ -15567,6 +15571,31 @@ window.__ModuleLoader__.load({ } }, [sessionId, repoRoot, pickRepo, refresh]) + useEffect(() => { + const watcher = () => { setRevealTick((value) => value + 1) } + panelRevealWatchers.add(watcher) + return () => { panelRevealWatchers.delete(watcher) } + }, []) + + useEffect(() => { + const seat = { sessionId: sessionId, visible: () => revealVisibleRef.current === true } + panelSeats.add(seat) + return () => { panelSeats.delete(seat) } + }, [sessionId]) + useEffect(() => { revealVisibleRef.current = props.visible === true }, [props.visible]) + + useEffect(() => { + if (props.visible !== true) return + const request = takePanelReveal(sessionId) + if (request !== null) { + revealRootRef.current = request.repoRoot + setView('history') + if (request.repoRoot !== repoRoot) { pickRepo(request.repoRoot); return } + } + if (revealRootRef.current === null || revealRootRef.current !== repoRoot) return + setRevealPending((value) => value + 1) + }, [revealTick, props.visible, sessionId, repoRoot, pickRepo]) + const openDiff = useCallback(async (seed) => { const key = JSON.stringify([base, seed]) const now = Date.now() @@ -16763,6 +16792,13 @@ window.__ModuleLoader__.load({ setNote(t('note.noChanges')) } + useEffect(() => { + if (revealRootRef.current === null) return + if (revealRootRef.current !== repoRoot || summary === null) return + revealRootRef.current = null + showWorkingDiff() + }, [revealPending, repoRoot, summary]) + const stashMenu = (event) => { const count = summary === null ? 0 : summary.stashCount openMenuAt(event, [ @@ -18368,6 +18404,9 @@ window.__ModuleLoader__.load({ '.dig-cs-changes{color:var(--dsw-alias-state-warn-primary)}', '.dig-cs-behind{color:var(--dsw-alias-state-business-primary)}', '.dig-cs-ahead{color:var(--dsw-alias-state-success-primary)}', + '.dig-cs-stats{display:inline-flex;align-items:center;gap:2px;padding:0 4px;margin:0 -4px;border:none;border-radius:var(--dsw-radius-sm,8px);background:transparent;color:inherit;font:inherit;flex:none;cursor:pointer}', + '.dig-cs-stats:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}', + '.dig-cs-stats:disabled{cursor:default}', /* v0.19.12: file-level add/del split rides INSIDE the ± chip at one step down (11px) so the two +/− groups read as two levels — small green/red = FILES, full-size green/red = LINES. */ @@ -18578,6 +18617,63 @@ window.__ModuleLoader__.load({ } } + const PANEL_REVEAL_TTL_MS = 10000 + let panelReveal = null + const panelRevealWatchers = new Set() + const panelSeats = new Set() + + function visiblePanelSeatOf(sessionId) { + for (const seat of panelSeats) { + if (seat.sessionId === sessionId && seat.visible() === true) return seat + } + return null + } + + function requestPanelReveal(sessionId, repoRoot) { + if (typeof sessionId !== 'string' || sessionId === '') return + if (typeof repoRoot !== 'string' || repoRoot === '') return + panelReveal = { sessionId: sessionId, repoRoot: repoRoot, at: Date.now() } + for (const watcher of panelRevealWatchers) { + try { watcher() } catch (error) { void error } + } + } + + function takePanelReveal(sessionId) { + const request = panelReveal + if (request === null) return null + if (request.sessionId !== sessionId) return null + panelReveal = null + if (Date.now() - request.at > PANEL_REVEAL_TTL_MS) return null + return request + } + + function gitPanelSeatOf(ctx) { + const services = sidebarServicesOf(ctx) + const betterSidebar = services.betterSidebar + if (betterSidebar !== undefined && betterSidebar !== null && typeof betterSidebar.openTab === 'function') return 'betterSidebar' + const sidebarRight = services.sidebarRight + if (sidebarRight !== undefined && sidebarRight !== null && typeof sidebarRight.openTab === 'function') return 'native' + return null + } + + function openGitPanel(ctx, sessionId, cwd, repoRoot) { + const seat = gitPanelSeatOf(ctx) + if (seat === null) return false + requestPanelReveal(sessionId, repoRoot) + const services = sidebarServicesOf(ctx) + if (seat === 'betterSidebar') { + try { + services.betterSidebar.openTab({ type: TAB_ID, target: 'right' }, { sessionId: sessionId, cwd: cwd }) + return true + } catch (error) { void error } + } + try { + services.sidebarRight.openTab(NATIVE_KIND) + return true + } catch (error) { void error } + return false + } + /* The pill's own on/off switch: the same read the conversation tab's placement switch uses — row Config when the host serves it, always-on before it answers (default ON per the request). */ @@ -19125,6 +19221,31 @@ window.__ModuleLoader__.load({ return title })() + const panelSeat = gitPanelSeatOf(ctx) + const openPanelDiff = () => { + if (repoRoot === null) return + if (visiblePanelSeatOf(sessionId) !== null) { requestPanelReveal(sessionId, repoRoot); return } + openGitPanel(ctx, sessionId, cwd, repoRoot) + } + const statsChildren = [] + if (changesCount !== null && changesCount > 0) { + statsChildren.push(E('span', { className: 'dig-cs-badge dig-cs-changes', key: 'changes' }, '±' + String(changesCount), + fileSplit.added > 0 ? E('span', { className: 'dig-cs-split dig-cs-add' }, '+' + String(fileSplit.added)) : null, + fileSplit.deleted > 0 ? E('span', { className: 'dig-cs-split dig-cs-del' }, '−' + String(fileSplit.deleted)) : null)) + } + if (linesLive !== null && (linesLive.additions > 0 || linesLive.deletions > 0)) { + statsChildren.push(E('span', { className: 'dig-cs-lines', key: 'lines' }, + linesLive.additions > 0 ? E('span', { className: 'dig-cs-badge dig-cs-add' }, '+' + String(linesLive.additions)) : null, + linesLive.deletions > 0 ? E('span', { className: 'dig-cs-badge dig-cs-del' }, '−' + String(linesLive.deletions)) : null)) + } + const statsNode = statsChildren.length === 0 ? null : E('button', { + type: 'button', + className: 'dig-cs-stats', + disabled: panelSeat === null, + title: panelSeat === null ? t('diff.sidebar.unavailable') : changesTitle + ' · ' + t('action.showDiff'), + onClick: panelSeat === null ? undefined : openPanelDiff, + }, statsChildren) + const openBranchMenu = async () => { setMenu('branch') /* A warm page (panel or prewarm) fills the list this tick; the fetch @@ -19204,16 +19325,7 @@ window.__ModuleLoader__.load({ E(Icon, { name: 'branch', size: 13 }), E(ComposerMarqueeName, { text: detached === true ? t('composer.detached') : branchName }), E(Icon, { name: 'chevron', size: 10 })) : null, - changesCount !== null && changesCount > 0 - ? E('span', { className: 'dig-cs-badge dig-cs-changes', title: changesTitle }, '±' + String(changesCount), - fileSplit.added > 0 ? E('span', { className: 'dig-cs-split dig-cs-add' }, '+' + String(fileSplit.added)) : null, - fileSplit.deleted > 0 ? E('span', { className: 'dig-cs-split dig-cs-del' }, '−' + String(fileSplit.deleted)) : null) - : null, - linesLive !== null && (linesLive.additions > 0 || linesLive.deletions > 0) - ? E('span', { className: 'dig-cs-lines' }, - linesLive.additions > 0 ? E('span', { className: 'dig-cs-badge dig-cs-add', title: changesTitle }, '+' + String(linesLive.additions)) : null, - linesLive.deletions > 0 ? E('span', { className: 'dig-cs-badge dig-cs-del', title: changesTitle }, '−' + String(linesLive.deletions)) : null) - : null, + statsNode, behind > 0 ? E('span', { className: 'dig-cs-badge dig-cs-behind', title: t('composer.behindHint') }, '↓' + String(behind)) : null, ahead > 0 ? E('span', { className: 'dig-cs-badge dig-cs-ahead', title: t('composer.aheadHint') }, '↑' + String(ahead)) : null, error !== '' ? E('span', { className: 'dig-cs-error', title: error }, '×') : null, diff --git a/tests/smoke.mjs b/tests/smoke.mjs index 96980cf..ad8ecba 100644 --- a/tests/smoke.mjs +++ b/tests/smoke.mjs @@ -1961,6 +1961,53 @@ test('the composer badge splits files added/deleted and lazily sums uncommitted assert.equal((client.match(/'composer\.linesHint':/g) || []).length, 21) }) +test('the composer change counters open the Git panel on the working-tree diff', () => { + const start = client.indexOf('const PANEL_REVEAL_TTL_MS') + assert.ok(start >= 0, 'the panel reveal store must exist at module level') + const end = client.indexOf('function composerStatusEnabled(', start) + assert.ok(end > start, 'the reveal store must sit beside the composer store') + const store = new Function(client.slice(start, end) + '; return { requestPanelReveal: requestPanelReveal, takePanelReveal: takePanelReveal, visiblePanelSeatOf: visiblePanelSeatOf, watchers: panelRevealWatchers, seats: panelSeats, PANEL_REVEAL_TTL_MS: PANEL_REVEAL_TTL_MS }')() + let notified = 0 + store.watchers.add(() => { notified += 1 }) + store.requestPanelReveal('s1', '/repo/a') + assert.equal(notified, 1, 'a request wakes the mounted panel tree') + assert.equal(store.takePanelReveal('s2'), null, 'another session never eats the request') + const taken = store.takePanelReveal('s1') + assert.equal(taken === null ? '' : taken.repoRoot, '/repo/a', 'the request carries the repository the pill was showing') + assert.equal(store.takePanelReveal('s1'), null, 'a request is consumed once') + const realNow = Date.now + try { + store.requestPanelReveal('s1', '/repo/a') + Date.now = () => realNow() + store.PANEL_REVEAL_TTL_MS + 1 + assert.equal(store.takePanelReveal('s1'), null, 'a stale click never lands on a panel opened much later') + } finally { + Date.now = realNow + } + store.requestPanelReveal('', '/repo/a') + assert.equal(store.takePanelReveal(''), null, 'a request without a session is dropped') + const hiddenSeat = { sessionId: 's1', visible: () => false } + store.seats.add(hiddenSeat) + assert.equal(store.visiblePanelSeatOf('s1'), null, 'a hidden panel is not a target for the reveal') + const shownSeat = { sessionId: 's1', visible: () => true } + store.seats.add(shownSeat) + assert.equal(store.visiblePanelSeatOf('s1'), shownSeat, 'a visible panel takes the reveal instead of a second seat opening') + assert.equal(store.visiblePanelSeatOf('s2'), null, 'seats are scoped to their own session') + + assert.match(client, /className: 'dig-cs-stats'/, 'the counters render as one clickable group') + assert.match(client, /title: panelSeat === null \? t\('diff\.sidebar\.unavailable'\) : changesTitle \+ ' · ' \+ t\('action\.showDiff'\)/, 'the tooltip keeps the breakdown and names the verb') + assert.match(client, /onClick: panelSeat === null \? undefined : openPanelDiff/, 'clicking the counters is the diff verb') + assert.match(client, /if \(visiblePanelSeatOf\(sessionId\) !== null\) \{ requestPanelReveal\(sessionId, repoRoot\); return \}/, 'an already-visible panel takes the request instead of a second seat') + assert.match(client, /openTab\(\{ type: TAB_ID, target: 'right' \}/, 'better-sidebar opens the Git tab on the right') + assert.match(client, /services\.sidebarRight\.openTab\(NATIVE_KIND\)/, 'the native fallback opens the panel kind') + assert.match(client, /panelRevealWatchers\.add\(watcher\)/, 'the panel subscribes to the pill request') + assert.match(client, /panelSeats\.add\(seat\)/, 'mounted panels publish their seat') + assert.match(client, /if \(request\.repoRoot !== repoRoot\) \{ pickRepo\(request\.repoRoot\); return \}/, 'a request for another repository moves the panel there first') + assert.match(client, /revealRootRef\.current !== repoRoot \|\| summary === null/, 'the diff waits for the matching summary') + assert.match(client, /revealRootRef\.current = null\n showWorkingDiff\(\)/, 'the accept reuses the working-tree diff funnel') + assert.match(cssRule('.dig-cs-stats'), /cursor:pointer/, 'the counters read as clickable') + assert.match(cssRule('.dig-cs-stats:disabled'), /cursor:default/, 'no pointer cursor without a right sidebar') +}) + test('long pill names widen to 260px and scroll only on hover, seamlessly (v0.19.13)', () => { // The cap widens 150→260; past it the label switches to a duplicated-chunk // structure measured after paint, and ONLY :hover starts the marquee —