From bc66e8dc53c7ca5cc8e63506dffdff834980e3b7 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Sun, 8 Nov 2026 12:18:50 +0800 Subject: [PATCH] feat(changes): add reveal/open exits to the diff content view (#1092) --- CHANGELOG.md | 2 ++ CHANGELOG_EN.md | 2 ++ src/client/changes/DiffPane.tsx | 38 +++++++++++++++++++++++- tests/diff-git-target.spec.tsx | 52 +++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e103c6d..67dc7207 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,8 @@ - 🧪 测试:`tests/file-stream-route.spec.ts` 新增 Range 真机用例(窗口 / 后缀 / 越界钳制 / 416 / 回退 200 / 视频 MIME)与 `byteRangeOf` 单测;`tests/builtins.spec.ts` 钉住 `media` 的认领面与 `mediaUrl` 策略;`tests/smoke.spec.ts` 钉住媒体 MIME 表;`tests/locales.spec.ts` 的 21 种语言键集对齐覆盖新增 `viewerMedia` / `mediaUnplayable`。 +- 🧭 **Diff/内容视图补上「在资源管理器中定位 / 在应用中打开」出口**([#1092](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1092)):从对话 diff 卡片进入的文件视图不再是死胡同;宿主可打开本地路径时,页头在刷新/展开旁提供这两个入口,不可用的部署不显示死按钮。 + ### v0.30.1 - 🎯 **设置页「侧边卡片」的导航图标不再叠成两个**:插件此前按"宿主设置导航还没有图标通道"的老假设,用 CSS 把兜底齿轮藏起来、再画自己的图标;宿主早已提供按 section id 寻址的 `settings.section.icon` 插槽,而且图标的 DOM 外面多了一层 span,老选择器失效后兜底 SVG 露了出来,与插件图标并排显示。现在改为**走宿主插槽**提供图标,删掉标记 + CSS 遮罩那一套(顺带去掉了一个监听整个 document 的 MutationObserver)。 diff --git a/CHANGELOG_EN.md b/CHANGELOG_EN.md index b45a1bf4..2fb77e01 100644 --- a/CHANGELOG_EN.md +++ b/CHANGELOG_EN.md @@ -42,6 +42,8 @@ - 🧪 Tests: `tests/file-stream-route.spec.ts` gains real-server Range cases (window / suffix / clamp / 416 / 200 fallback / video MIME) plus `byteRangeOf` unit tests; `tests/builtins.spec.ts` pins the `media` claim surface and its `mediaUrl` strategy; `tests/smoke.spec.ts` pins the media MIME table; the 21-language key-set equality in `tests/locales.spec.ts` covers the new `viewerMedia` / `mediaUnplayable` keys. +- 🧭 **The Diff/content view now offers reveal-in-file-manager and open-in-app exits** ([#1092](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1092)): a file reached from a chat diff card is no longer a dead end. When the host can open workspace paths, the pane header shows both controls next to refresh/expand; desktop-less deployments hide them instead of offering dead buttons. + ### v0.30.1 - 🎯 **The "Side card" settings row no longer shows two icons**: the plugin still assumed the settings navigation had no icon channel, so it hid the fallback gear with CSS and painted its own glyph. The shell has long since exposed a `settings.section.icon` slot addressed by section id, and it now wraps the nav icon in a span — the stale `> svg:first-child` rule stopped hiding the fallback, so both glyphs rendered side by side. The row now contributes its icon **through the slot**, and the marker + CSS-mask apparatus is gone (along with a document-wide MutationObserver). diff --git a/src/client/changes/DiffPane.tsx b/src/client/changes/DiffPane.tsx index 85d9e2ca..81711aed 100644 --- a/src/client/changes/DiffPane.tsx +++ b/src/client/changes/DiffPane.tsx @@ -17,7 +17,7 @@ * the pane is byte-for-byte the strip-less preview of before. */ import { useEffect, useMemo, useRef, useState, type PointerEvent as ReactPointerEvent, type ReactNode } from 'react' -import { IconCloseOutlineRegular, IconRefreshOutlineRegular, IconRightUpOutlineRegular, MarkdownDelegateProvider, MarkdownText } from '@deepseek-ai/dsh-client-ui-primitives' +import { IconCloseOutlineRegular, IconFolderOpenOutlineRegular, IconRefreshOutlineRegular, IconRightUpOutlineRegular, IconShareOutlineRegular, MarkdownDelegateProvider, MarkdownText } from '@deepseek-ai/dsh-client-ui-primitives' import type { Context } from '../../context-types.ts' import type { SessionScope } from '../api.ts' import { api, htmlUrl } from '../api.ts' @@ -38,6 +38,7 @@ import { parseReadContent, parseReadLines, type FileOp } from './ops.ts' import { redactText } from '../redact.ts' import { createMarkdownPathImages } from '../markdown-images.ts' import { markdownTextProps } from '../markdown-labels.tsx' +import { createOpenInApp } from '../open-in-app.ts' import { useMarkdownSurface } from '../use-markdown-surface.ts' import { splitMermaidBlocks } from '../mermaid-blocks.ts' import { LazyMermaidMarkdown } from '../mermaid-lazy.tsx' @@ -258,6 +259,25 @@ export function DiffPane({ target, ctx, scope, height, onHeightCommit, onClose, * content view, and the only one carrying a `path`). */ const gitWorktree = gitRef !== null && gitRef.kind === 'worktree' ? gitRef : null const { loading, error, diffText, untracked, refresh, resolveFold } = useGitDiffTarget(gitRef, scope) + /** The host's "open / reveal outside the GUI" capability. Probed once per + * pane: a desktop-less deployment hides the two exits instead of offering + * dead buttons. */ + const openInApp = useMemo(() => createOpenInApp(ctx), [ctx]) + const [appReady, setAppReady] = useState(() => openInApp.available() === true) + useEffect(() => { + const known = openInApp.available() + if (known !== null) { + setAppReady(known) + return + } + let cancelled = false + void openInApp.probe().then((ok) => { + if (!cancelled) setAppReady(ok) + }).catch(() => { + if (!cancelled) setAppReady(false) + }) + return () => { cancelled = true } + }, [openInApp]) // ── The pane's views, resolved BEFORE anything loads: which tabs exist and // which one is on screen. Computed from raw target facts (`kind` and @@ -611,6 +631,22 @@ export function DiffPane({ target, ctx, scope, height, onHeightCommit, onClose, /> )} + {contentAbs !== '' && appReady && ( + <> + } + label={t('editorOpenInFileManager')} + onClick={() => { void openInApp.reveal(contentAbs) }} + /> + } + label={t('openWithMenu')} + onClick={() => { void openInApp.open(contentAbs) }} + /> + + )} {redactionHit && ( {t('changesRedactBanner')} )} diff --git a/tests/diff-git-target.spec.tsx b/tests/diff-git-target.spec.tsx index 57d64a25..ca6d65c0 100644 --- a/tests/diff-git-target.spec.tsx +++ b/tests/diff-git-target.spec.tsx @@ -172,6 +172,58 @@ describe('useGitDiffTarget through the inline preview pane (DiffPane)', () => { }) }) +describe('DiffPane external exits', () => { + it('offers reveal/open when the host can open workspace paths', async () => { + const worktree: SidebarDiffRef = { kind: 'worktree', path: 'src/a.ts', staged: false } + vi.spyOn(api, 'gitDiff').mockResolvedValue({ diff: '' }) + const openWorkspacePath = vi.fn(async () => ({ ok: true })) + const ctx = { + get: (name: string) => name === 'remote' + ? { session: { + canOpenWorkspacePath: async () => ({ ok: true, value: true }), + workspacePathApplications: async () => ({ ok: true, value: [] }), + openWorkspacePath, + } } + : undefined, + } as unknown as Context + + const container = document.createElement('div') + document.body.append(container) + const root: Root = createRoot(container) + try { + act(() => { + root.render(createElement(DiffPane, { + target: { kind: 'git', ref: worktree }, + ctx, + scope: SCOPE, + height: 300, + onHeightCommit: () => {}, + onClose: () => {}, + onExpand: () => {}, + })) + }) + await flushEffects() + await act(async () => { await new Promise(resolve => { setTimeout(resolve, 20) }) }) + + const reveal = container.querySelector(`button[aria-label="${t('editorOpenInFileManager')}"]`) as HTMLButtonElement | null + const open = container.querySelector(`button[aria-label="${t('openWithMenu')}"]`) as HTMLButtonElement | null + expect(reveal).not.toBeNull() + expect(open).not.toBeNull() + + act(() => { reveal!.click() }) + await flushEffects() + expect(openWorkspacePath).toHaveBeenCalledWith({ path: '/p/src/a.ts', action: 'reveal' }) + + act(() => { open!.click() }) + await flushEffects() + expect(openWorkspacePath).toHaveBeenCalledWith({ path: '/p/src/a.ts' }) + } finally { + act(() => { root.unmount() }) + container.remove() + } + }) +}) + describe('useGitDiffTarget through the dedicated diff tab (DiffTab)', () => { it('loads a commit patch into the shared renderer', async () => { vi.spyOn(api, 'gitCommitDiff').mockResolvedValue({ diff: STAGED_PATCH })