fix(forge): fit the review layer lens to the file tree width

The lens above the file tree sizes each segment to its label and drops
the counts into each segment's hover text when they do not fit, so no
layer name is cut short. The tree keeps the width the lens needs for
the names alone as its least width, measured in the current language.
This commit is contained in:
LegGasai committed 2026-11-13 17:50:58 +08:00
1 parent de594f702d
commit 16c7499d51
9 files changed
+230 -31

No files matched your search

@@ -15,8 +15,8 @@
en: d152484eb41ac6b4
zh: 2f8a621b991260a1
/deepseek-ai-dsh-experimental-client-ui-forge/use-this-package:
en: 705f7f143fc7d6fb
zh: e757a4bf6b0ebce1
en: 348ca0e28bc37737
zh: 2d518a4504a7ff33
/deepseek-ai-dsh-experimental-client-ui-forge/understand-the-implementation:
en: 6dd304b2ee1d1771
zh: 9749536a0672dc8f
@@ -40,7 +40,7 @@ Panel text follows the application language: Chinese, English, Japanese, Spanish
- **Local changes card** — whenever the `branch` scope changes files, independently of bound change requests, a card above the change requests names the ref it compares with, such as `HEAD → origin/main`, which is always the default base below, and shows the added and deleted lines and the number of files, which open the changes view; its file list, which names files as the changes view does, opens the view at one file. Create change request, offered when the code host repository is recognized and no open change request (including drafts) has the checked-out branch as its head, sends the Session a user message in the UI language that asks the Agent to create a change request for these changes, and a toast reports whether it was sent.
- **Changes view** — The Changes row of an expanded change request card and the local changes card open a right-sidebar tab that lists the changed files. The local tab is named Local changes and shows Branch by default: the working tree and untracked files against the fork point. Its header names the checked-out branch, or the abbreviated commit on a detached HEAD, and the base branch, which opens a searchable menu: first Default, the base commit of the worktree the Session created, else the merge base of HEAD with the default branch of the code host remote, then remote-tracking and then local branches, each most recently committed first, without the checked-out branch and, outside a created worktree, without the remote-tracking branch Default already names. Typing filters the listed rows at once and lists the branches whose names contain the text, ignoring case, after a short pause; Enter chooses the first row. Choosing another branch compares with the merge base of HEAD and that branch. The tab keeps the choice while other scopes show; closing the tab or reloading the application returns it to Default. When the chosen branch is gone, its name is struck through, and when it shares no history with HEAD, the view says so as well; both offer Use the default base branch instead of Retry. A narrow view hides the note that uncommitted changes count, then the checked-out branch. Uncommitted compares them with HEAD, Unstaged with the index, and Staged compares the index with HEAD. A change request view shows the host's diff at its head and says how many commits the checked-out branch has beyond that head when it is the change request's head branch. The toolbar jumps to a file, totals the changed lines, refreshes, and switches between two columns and one and between wrapped and cut long lines. The toolbar and the header each keep one line: as the toolbar narrows, the line totals, expanding all files, two columns, and wrapping move into a More menu first, then the test file switch, with the viewed progress label shortened to a bare count beside its ring, and then refresh, while header buttons keep their labels on one line and the menus and title shorten. Visited changes tabs stay mounted across tab and Session switches, hiding the sidebar, and docking changes, preserving file folds, revealed large files, expanded context, layout, and scroll position while the diff is unchanged. Hidden changes views release their panel subscription and defer diff reads; returning reads again only when the latest head or local summary differs. A refresh that replaces the diff discards expanded context, and changed content may move the reading position. Temporary menus close when the view is hidden. Closing the tab or reloading the application discards this progress. Each file is a separate card, with a tinted header that stays at the top while its lines scroll. Files are named before their directories, which use smaller subdued type and shorten first; hovering one shows its complete path, and both paths for a renamed file. Each file shows badges for a new, deleted, or renamed file, the last naming the old file name, or the old path when only the directory changed, and, in the Branch scope, an untracked one, and a menu that copies its path and opens the whole file in the sidebar for local changes or its page at the head in the browser for a change request. When the header is narrow, the path, the badges, and Changed since viewed shorten, so the line counts, Viewed, and the menu stay whole. Unchanged lines between hunks collapse into rows that expand from the file's new side: the working tree, the index for Staged, or the head commit through the code host; a file that changed after the diff was read stays collapsed until the view reads again. A row of at most 20 lines expands with one click. A longer row expands 20 lines at a time, down from the hunk above it or up from the hunk below it, the row before the first hunk only up and the row after the last hunk only down, and shows how many lines it still hides; the first click on the unknown lines after the last hunk reads the file and shows their first 20. A binary file and an untracked file over `maxDiffBytes` show a note instead of their lines, a file whose hunks draw more than 1,000 lines starts as one collapsed strip that names its changed lines and draws them when opened, and a file below files that change more than 5,000 lines starts collapsed. The view reads again on Refresh and the page refresh shortcut, on each navigation, when the change request's head moves, and when the Branch scope's summary changes; a change request's view first waits for the status that names its head, unless no provider serves it or that poll failed. When the head moved past the latest status, the view keeps loading and reads again at the head of a status later than the one the read started with, at once when that status arrived during the read. While a read replaces changes already shown, the Refresh iLine truncated
- **Review layers, test files, viewed files, and commits** — Above the file tree, the lens keeps All files or the files of one layer, Interface, Implementation, or Tests, each with its count; where no tree shows, the toolbar offers the lens as a menu. The repository decides first: a file whose root `.gitattributes` sets `dsh-review-layer=test`, `interface`, or `implementation` is in that layer, and one it marks `linguist-generated` is in Tests. Next come the optional `testPaths` and `interfacePaths` globs, which add to the built-in rules and are empty by default. The built-in rules then follow common conventions: test directories and files of Jest, Vitest, `go test`, pytest, RSpec, XCTest, and .NET, snapshots, locale catalogs, and lockfiles are Tests; package manifests, type declarations, headers, stubs, and interface definitions such as Protocol Buffers, GraphQL, and OpenAPI are Interface. Every other file is in Implementation. For example, `*_test.go dsh-review-layer=test` or `api/**/*.yaml dsh-review-layer=interface` in `.gitattributes` records a repository's own convention. Hide test files leaves Tests out of the file tree and the diff without listing them, and disables the Tests lens. Viewed on a file header marks that change of the file viewed and collapses it; the toolbar shows how many of the shown files are viewed, as a ring filled to the viewed share and a label such as 2 / 3 viewed, and `V` marks or clears the file being read: the file holding the focus or the text cursor, else the file at the top of the view. A file whose change differs from the change it was marked at shows Changed since viewed and expands again. A change of the file mode alone, such as `chmod +x`, also counts as a new change. A change request's view of all its commits uses the viewed marks its provider keeps on the code host, as the GitHub provider does: the view reads them with the diff, shows a mark at once, and saves it at the displayed head, keeping that file's checkbox disabled until the host answers; a file GitHub reports as changed since it was viewed shows Changed since viewed. A mark the host refuses, or one that new commits made stale, returns to its previous state, and a toast says why; a mark the host may have saved without confirming it stays, and a toast says to refresh to see where it stands. When the marks cannot be read, a notice says so and offers Retry, and no file can be marked. Hovering a checkbox tells where its mark is kept. Other marks are kept in this browser per Session, source, path, and change digest, so they survive closing the tab and reloading, and the tabs of one Session share them: a mark in one tab appears in the others and keeps their marks. All commits beside Submit review, and beside the base branch in the Branch scope, lists the commits oldest first, read once until the head, the local branch or base, or a refresh changes them; a click shows one commit and a Shift click the commits from the last one clicked, which must follow each other as first parents: a run that leaves that line, such as one across a merged branch, keeps the menu open and says why; the view then shows those commits' changes, reads unchanged lines at the last of them, and offers Add to input but no GitHub comment or review. Branch commits exclude uncommitted and untracked files. Another base or scope returns to all commits, and chosen commits that are gone or no longer one run offer Show all commits.
- **Review layers, test files, viewed files, and commits** — Above the file tree, the lens keeps All files or the files of one layer, Interface, Implementation, or Tests, each with its count; when the counts do not fit the tree's width, it shows the layer names alone and each count in the hover text of its layer. Where no tree shows, the toolbar offers the lens as a menu. The repository decides first: a file whose root `.gitattributes` sets `dsh-review-layer=test`, `interface`, or `implementation` is in that layer, and one it marks `linguist-generated` is in Tests. Next come the optional `testPaths` and `interfacePaths` globs, which add to the built-in rules and are empty by default. The built-in rules then follow common conventions: test directories and files of Jest, Vitest, `go test`, pytest, RSpec, XCTest, and .NET, snapshots, locale catalogs, and lockfiles are Tests; package manifests, type declarations, headers, stubs, and interface definitions such as Protocol Buffers, GraphQL, and OpenAPI are Interface. Every other file is in Implementation. For example, `*_test.go dsh-review-layer=test` or `api/**/*.yaml dsh-review-layer=interface` in `.gitattributes` records a repository's own convention. Hide test files leaves Tests out of the file tree and the diff without listing them, and disables the Tests lens. Viewed on a file header marks that change of the file viewed and collapses it; the toolbar shows how many of the shown files are viewed, as a ring filled to the viewed share and a label such as 2 / 3 viewed, and `V` marks or clears the file being read: the file holding the focus or the text cursor, else the file at the top of the view. A file whose change differs from the change it was marked at shows Changed since viewed and expands again. A change of the file mode alone, such as `chmod +x`, also counts as a new change. A change request's view of all its commits uses the viewed marks its provider keeps on the code host, as the GitHub provider does: the view reads them with the diff, shows a mark at once, and saves it at the displayed head, keeping that file's checkbox disabled until the host answers; a file GitHub reports as changed since it was viewed shows Changed since viewed. A mark the host refuses, or one that new commits made stale, returns to its previous state, and a toast says why; a mark the host may have saved without confirming it stays, and a toast says to refresh to see where it stands. When the marks cannot be read, a notice says so and offers Retry, and no file can be marked. Hovering a checkbox tells where its mark is kept. Other marks are kept in this browser per Session, source, path, and change digest, so they survive closing the tab and reloading, and the tabs of one Session share them: a mark in one tab appears in the others and keeps their marks. All commits beside Submit review, and beside the base branch in the Branch scope, lists the commits oldest first, read once until the head, the local branch or base, or a refresh changes them; a click shows one commit and a Shift click the commits from the last one clicked, which must follow each other as first parents: a run that leaves that line, such as one across a merged branch, keeps the menu open and says why; the view then shows those commits' changes, reads unchanged lines at the last of them, and offers Add to input but no GitHub comment or review. Branch commits exclude uncommitted and untracked files. Another base or scope returns to all commits, and chosen commits that are gone or no longer one run offer Show all commits.
- **Review threads** — A change request view overlays the review threads its code host read at the shown head. A thread on lines follows the row of its last line, on the side it was written on, or the collapsed unchanged lines that hold it; it shows the place it was written, each comment's avatar, author, time, and Markdown with raw HTML left out, and tags for the change request's author, bots, and comments still pending in the signed-in user's review. A resolved thread folds into one row that unfolds on request. Threads on a whole file open the file, and threads later commits made outdated gather after its lines in a section that shows the end of the hunk they were written on and offers View file at that commit, which reads the file at the commit they were written on with their lines marked. Chosen commits show only new-side threads whose lines number the last chosen commit. The file tree and each file header count unresolved threads. Each click on the count in a header goes to the file's next unresolved thread in the order the file shows them, threads the chosen commits do not hold last, and from the last back to the first; the Threads toolbar button opens the thread list, which groups the threads by file in file tree order and orders each file's threads the same way, shows the Unresolved, Resolved, or All threads, Unresolved first, and opens each thread at its place, choosing all commits for one the chosen commits do not hold. The list docks beside the files in a view at least 1,040px wide, floats over them in a narrower one and closes before it opens a thread there, and takes their whole width below 480px. The list names a truncated read. A thread offers Add to input, which quotes the whole thread, View on GitHub, and the writes the signed-in user may make. Without a pending review, its reply field replies at once, and its menu starts a pending review with the reply; with one, the field adds the reply to it, as GitHub adds every reply of the user to the pending review. Resolve thread and Unresolve thread change its state, and the menu of the user's own comment edits or deletes it after asking, saying when deleting the only comment deletes the thread. A resolved thread stays open while the user writes a reply or an edit in it. A write the code host refuses keeps the text and says why; a write whose outcome is unknown reads the threads again and asks the user to check them before trying again. Every write reads the threads again, since resolving a thread does not change a GitHub pull request's update time. Threads are read again at each status while the view shows, and from the code host after Refresh even while the panel keeps an earlier read; a failed read keeps the last threads and offers Retry, and a provider that does not read reviews shows none.
- **Extension API** — Other plugins extend the changes view through the [extension API](../../../docs/subsystems/forge.md#extension-api). A Host plugin registers a filter lens with `ctx.forgePanel.registerLens`, and a Client plugin names it with `ctx.forgeChanges.describeLens`; the toolbar then offers a Lens menu after Hide test files, which keeps the files of the chosen layer that the chosen lens keeps, counts each lens's files once it ran, and folds the hunks a kept file's lens is not about into a row that shows them. A running lens shows its progress on the menu button; a failed, refused, or interrupted run says why and offers Retry and Clear lens, and a lens whose plugin unloads stops filtering with a toast. While no lens is chosen, the menu folds into the More menu with the test switch. `ctx.forgeChanges` also opens a view with a file and a lens chosen and registers line annotation sources, whose notes stack after the comments and threads of their last line, in the column of their side, whole-file notes first and notes on an earlier change last, at most `maxAnnotationsPerFile` in a file. Plugins add toolbar tools, which fold into the More menu first, file menu rows, comment form buttons after Add to input, and card head buttons through the `forge.changes.toolbar`, `forge.changes.file.menu`, `forge.diff.comment.actions`, and `forge.change-request.card.actions` slots.
@@ -50,7 +50,7 @@ The diff follows the file tree’s depth-first order: directories before files,
`gitCommand`, `gitTimeoutMs`, `graceMs`, `maxOutputBytes`, `readinessTimeoutMs`, `maxBranches`, `worktreePrefix`, `maxDiffBytes`, `maxUntrackedFiles`, `maxCachedDiffBytes`, `maxCachedReviewBytes`, `reviewRefreshMs`, `maxCommits`, `testPaths`, `interfacePaths`, `lensTimeoutMs`, `maxLensReadBytes`, `maxCachedLensBytes`, and `maxAnnotationsPerFile` are listed in the [configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-experimental-client-ui-forge).
All files opens a searchable directory tree with the selected file scrolled to its middle. Single-child directories share a row, and renamed files also match their old path. A wide changes pane shows the same tree beside the diff; its File tree toolbar button cycles through left, right, and hidden, starting on the left. Its accessible name describes the next action, and focus stays on the button when it moves or hides the tree. The search, folds, selection, and width survive moving or hiding the tree and switching tabs or Sessions. Drag the divider or use its arrow keys to resize the tree. Files and folders reserve the same disclosure column so each child is indented from its parent. Local changes and each PR retain separate tabs. Select code text or use line numbers to select a range within one displayed hunk and side; text selection and copying stay on the starting side. The plus button opens the plain-text comment editor. With a mouse, hovering a line also shows a plus beside its line number, which stays clickable, on the hovered side in two columns and on the line's own side in one column; pressing it selects that line, dragging extends the range on that side, and releasing opens the editor. Several editors can stay open at once, and choosing the range of an open one focuses it again. In two columns, each comment sits under its own side of the row, so a left and a right comment share that row side by side, each continuing its line’s background. It accepts newlines and IME composition; only its action buttons submit the comment. Drag its lower edge to adjust the height. Add to input inserts a removable quote into the main composer that shows the file name, side and lines, and comment, and on hover the file path; multiple quotes are sent together only when the user sends that composer. Once the review threads are read and the user may review, the split button adds the comment to the user's pending review on the code host, starting one when there is none; the comment then shows as a thread tagged Pending, which only the user sees until the review is submitted. Its menu publishes a single comment immediately and is absent while the user has a pending review. Agent references and published comments remain beside their code. Request changes requires a review summary; the dialog explains this beside the summary field and announces the requirement when the decision changes. Submit review in the PR title bar opens a centered dialog showing only the pending count, summary, and Comment, Approve, or Request changes. With a pending review, it submits that review, keeping a submission whose outcome is unknown blocked until the user checks GitHub, as a direct submission is, and Discard review deletes the review and its comments after a confirmation; without one, it publishes the summary as one review. Decisions the code host does not let the user record are unavailable, such as Approve and Request changes on the user's own pull request on GitHub; when only Comment remains, the dialog says so. The view's copy names the code host and its word for a change request, such as GitHub and PR, after the change request's provider. Added and deleted files show only their populated line-number column. The summary, decision, and records of Agent references and published comments are stored in this browser per Session and tab, including the original PR head commit. Switching Sessions or hiding the pane retains them; closing the tab clears them, and reopening starts an empty summary. The pending review, published GitHub comments, and references already added to the main composer are unaffected. Comment drafts an earlier version kept in this browser stay beside their code tagged Browser draft and can be edited, deleted, or added to the pending review; they keep Submit review disabled while a pending review exists, and without one Submit review publishes them with the summary. Records whose code changed remain visible below their file, or after the diff when the file is absent. A changed head requires fresh line selections. While the tab remains open, an uncertain write stays blocked across reloads until the user checks GitHub and explicitly permits another submission.
All files opens a searchable directory tree with the selected file scrolled to its middle. Single-child directories share a row, and renamed files also match their old path. A wide changes pane shows the same tree beside the diff; its File tree toolbar button cycles through left, right, and hidden, starting on the left. Its accessible name describes the next action, and focus stays on the button when it moves or hides the tree. The search, folds, selection, and width survive moving or hiding the tree and switching tabs or Sessions. Drag the divider or use its arrow keys to resize the tree, which stays at least as wide as the lens above it needs to show the layer names whole. Files and folders reserve the same disclosure column so each child is indented from its parent. Local changes and each PR retain separate tabs. Select code text or use line numbers to select a range within one displayed hunk and side; text selection and copying stay on the starting side. The plus button opens the plain-text comment editor. With a mouse, hovering a line also shows a plus beside its line number, which stays clickable, on the hovered side in two columns and on the line's own side in one column; pressing it selects that line, dragging extends the range on that side, and releasing opens the editor. Several editors can stay open at once, and choosing the range of an open one focuses it again. In two columns, each comment sits under its own side of the row, so a left and a right comment share that row side by side, each continuing its line’s background. It accepts newlines and IME composition; only its action buttons submit the comment. Drag its lower edge to adjust the height. Add to input inserts a removable quote into the main composer that shows the file name, side and lines, and comment, and on hover the file path; multiple quotes are sent together only when the user sends that composer. Once the review threads are read and the user may review, the split button adds the comment to the user's pending review on the code host, starting one when there is none; the comment then shows as a thread tagged Pending, which only the user sees until the review is submitted. Its menu publishes a single comment immediately and is absent while the user has a pending review. Agent references and published comments remain beside their code. Request changes requires a review summary; the dialog explains this beside the summary field and announces the requirement when the decision changes. Submit review in the PR title bar opens a centered dialog showing only the pending count, summary, and Comment, Approve, or Request changes. With a pending review, it submits that review, keeping a submission whose outcome is unknown blocked until the user checks GitHub, as a direct submission is, and Discard review deletes the review and its comments after a confirmation; without one, it publishes the summary as one review. Decisions the code host does not let the user record are unavailable, such as Approve and Request changes on the user's own pull request on GitHub; when only Comment remains, the dialog says so. The view's copy names the code host and its word for a change request, such as GitHub and PR, after the change request's provider. Added and deleted files show only their populated line-number column. The summary, decision, and records of Agent references and published comments are stored in this browser per Session and tab, including the original PR head commit. Switching Sessions or hiding the pane retains them; closing the tab clears them, and reopening starts an empty summary. The pending review, published GitHub comments, and references already added to the main composer are unaffected. Comment drafts an earlier version kept in this browser stay beside their code tagged Browser draft and can be edited, deleted, or added to the pending review; they keep Submit review disabled while a pending review exists, and without one Submit review publishes them with the summary. Records whose code changed remain visible below their file, or after the diff when the file is absent. A changed head requires fresh line selections. While the tab remains open, an uncertain write stays blocked across reloads until the user checks GitHub and explicitly permits another submission.
-----
@@ -40,7 +40,7 @@ kind: "package-reference"
- **本地变更卡片**——`branch` 范围有文件变更时始终显示,不受已关联变更请求影响。变更请求列表上方的卡片显示比较的基准(例如 `HEAD → origin/main`,始终是下文的默认基准)以及新增、删除行数与文件数,点击打开变更视图;展开的文件列表像变更视图一样标出各个文件,点击某个文件时,变更视图定位到该文件。识别出代码托管仓库、且没有以当前检出分支为源分支的打开中变更请求(含草稿)时,卡片提供“创建变更请求”:它以界面语言向 Session 发送一条用户消息,请 Agent 为这些变更创建变更请求,并以 toast 报告是否已发送。
- **变更视图**——展开的变更请求卡片上的“变更”一行与本地变更卡片会打开一个右侧边栏标签页,列出所有变更的文件。本地标签页名为“本地变更”,默认显示“分支”:工作树与未跟踪文件相对于分叉点的变更。它的标题栏写出当前检出的分支(分离 HEAD 时为缩写提交)与基准分支;点击基准分支打开可搜索的菜单:最前面是“默认”,即 Session 创建的 worktree 的基准提交,否则是 HEAD 与代码托管远端默认分支的合并基准;其后依次是远程跟踪分支与本地分支,各按最近提交排序,不含当前检出的分支,不在所创建的 worktree 中时也不含“默认”已经指向的远程跟踪分支。输入文字会立即筛选已列出的行,短暂停顿后列出名称包含该文字(不区分大小写)的分支;按 Enter 选择第一行。选择其他分支后,与 HEAD 和该分支的合并基准比较。标签页切换到其他范围时仍保留这个选择;关闭标签页或重新加载应用后回到“默认”。所选分支已不存在时,它的名称显示删除线;它与 HEAD 没有共同历史时,视图同样给出说明;两种情况都提供“使用默认基准分支”而不是“重试”。视图较窄时,先隐藏“包含未提交的修改”,再隐藏当前分支。“未提交”与 HEAD 比较,“未暂存”与暂存区比较,“已暂存”比较暂存区与 HEAD。变更请求的视图显示托管平台在其 head 处的 diff;当前检出分支就是该变更请求的源分支时,还会说明本地分支比该 head 多出几个提交。工具栏可以跳到某个文件、汇总变更行数、刷新,并在左右对比与单栏对比、自动换行与截断长行之间切换。工具栏和标题栏各自保持一行:工具栏变窄时,先把变更行数、全部展开、左右对比与自动换行收进“更多视图选项”菜单,再收起“隐藏测试文件”开关,已审阅进度的文字缩短为圆环旁的计数,最后收起刷新;标题栏的按钮文字不换行,菜单和标题先缩短。访问过的变更标签页会在切换标签页与 Session、隐藏侧边栏及调整停靠位置时保持挂载,在 diff 未改变时保留文件折叠、大文件展开、上下文展开、布局与滚动位置。隐藏的变更视图释放面板订阅并推迟 diff 读取;返回时仅在最新 head 或本地摘要不同时重新读取。刷新替换 diff 后会丢弃展开的上下文,内容变化也可能移动阅读位置。视图隐藏时关闭临时菜单。关闭标签页或重新加载应用后不保留这些进度。每个文件是一张独立的卡片,带浅色底的标题在滚动时停在顶部。文件名在前,目录在后,用更小的浅色字显示,空间不够时目录先缩短;悬停时显示完整路径,重命名的文件显示新旧两条路径。每个文件带有新文件、已删除、重命名的标记(重命名标记写出原文件名,只换了目录时写出原路径),“分支”范围下的未跟踪文件还标“未提交”;文件菜单可以复制路径,本地变更可在侧边栏打开整个文件,变更请求可在浏览器中查看该文件在 head 处的页面。标题变窄时,路径、标记和“有新改动”会缩短,行数、“已审阅”和文件菜单始终完整显示。hunk 之间未变更的行折叠成一行,点击后从文件的新版本展开:工作树、“已暂存”时为暂存区,或经托管平台读取的 head 提交;读取 diff 之后文件又有修改时不会展开,直到视图重新读取。不超过 20 行的折叠行点一次全部展开。更长的折叠行每次展开 20 行,可以从上方 hunk 向下展开,也可以从下方 hunk 向上展开;第一个 hunk 之前的折叠行只能向上展开,最后一个 hunk 之后的只能向下展开;折叠行上显示还隐藏的行数。最后一个 hunk 之后行数未知的折叠行,第一次点击时读取文件并显示前 20 行。二进制文件与超过 `maxDiffBytes` 的未跟踪文件只显示一条说明;hunk 超过 1,000 行的文件先显示为一条写出变更行数的折叠条,点击后才绘制;前面的文件累计变更超过 5,000 行后,其后的文件默认收起。刷新与页面刷新快捷键、每次导航、变更请求的 head 变化,以及“分支”范围的摘要变化时,视图都会重新读取;变更请求的视图会先等到给出 head 的状态再读取,除非没有提供方服务它或那次轮询失败。head 已越过最新状态时,视图保持加载,等到比读取开始时更新的状态后按其 head 重新读取;该状态在读取期间已到达时立即重读。重新读取已显示的变更时,刷新图标会旋转。托管平台或其提供方因超过大小上限拒绝给出 diff 的变更请求(例如 GitHub 上输出超过提供方 `maxLine truncated
- **分层、测试文件、已审阅与提交**——文件树上方的分层透镜保留全部文件,或“接口”“实现”“测试”中一层的文件,并显示各自的数量;不显示文件树时,工具栏以菜单提供透镜。仓库的声明优先:根目录 `.gitattributes` 把文件设为 `dsh-review-layer=test`、`interface` 或 `implementation` 时,文件属于对应的层;标为 `linguist-generated` 的文件属于“测试”。其次是可选的 `testPaths` 与 `interfacePaths`,它们追加在内置规则之前,默认为空。最后是按常见约定写的内置规则:Jest、Vitest、`go test`、pytest、RSpec、XCTest 与 .NET 的测试目录和文件、快照、本地化目录与 lockfile 属于“测试”;包清单、类型声明、头文件、类型存根与 Protocol Buffers、GraphQL、OpenAPI 等接口定义属于“接口”。其余文件属于“实现”。例如在 `.gitattributes` 中写 `*_test.go dsh-review-layer=test` 或 `api/**/*.yaml dsh-review-layer=interface`,即可记录仓库自己的约定。“隐藏测试文件”让文件树与 diff 都不显示“测试”层,也不列出被隐藏的文件,同时停用“测试”透镜。文件标题上的“已审阅”把该文件的这次改动标为已审阅并折叠它;工具栏以按已审阅比例填充的圆环和“已审阅 2 / 3”这样的文字显示已显示文件中已审阅的数量,按 `V` 标记或取消当前阅读的文件:焦点或文本光标所在的文件,否则是视图顶部的文件。改动与标记时不同的文件显示“有新改动”并重新展开。只改文件模式(例如 `chmod +x`)也算新改动。变更请求的全部提交视图使用提供方保存在代码托管平台上的已审阅标记(GitHub 提供方即如此):视图随 diff 一起读取这些标记,勾选后立即显示,并在显示的 head 上保存,平台答复前该文件的复选框保持禁用;GitHub 报告为标记后又有改动的文件显示“有新改动”。平台拒绝或因新提交而过期的标记恢复原状,并以 toast 说明原因;平台可能已保存但未确认的标记保持不变,toast 提示刷新查看实际状态。无法读取标记时,提示条说明原因并提供“重试”,此时不能标记任何文件。悬停复选框会说明标记保存在哪里。其他标记按 Session、变更来源、路径与改动摘要保存在本浏览器中,关闭标签页或重新加载后仍在;同一 Session 的多个标签页共用这些标记:在一个标签页中标记,其他标签页随之更新,且不会覆盖它们的标记。“提交评审”左侧,以及“分支”范围中基准分支右侧的“全部提交”按从旧到新列出提交,读取一次后保留到 head、本地分支或基准变化或刷新为止;单击只看一个提交,按住 Shift 单击看从上次单击的提交到这个提交的连续多个提交,这些提交必须依次是后一个的第一父提交:离开这条链的范围(例如跨越已合并分支的范围)会让菜单保持打开并说明原因;此时视图显示这些提交的改动,在最后一个提交读取未变更的行,提供“添加到输入框”,但不提供 GitHub 评论或评审。“分支”的提交不含未提交与未跟踪的文件。换基准分支或范围后回到全部提交;所选提交已不存在或不再是一条链时提供“查看全部提交”。
- **分层、测试文件、已审阅与提交**——文件树上方的分层透镜保留全部文件,或“接口”“实现”“测试”中一层的文件,并显示各自的数量;文件树宽度放不下数量时,只显示各层名称,数量在悬停提示里。不显示文件树时,工具栏以菜单提供透镜。仓库的声明优先:根目录 `.gitattributes` 把文件设为 `dsh-review-layer=test`、`interface` 或 `implementation` 时,文件属于对应的层;标为 `linguist-generated` 的文件属于“测试”。其次是可选的 `testPaths` 与 `interfacePaths`,它们追加在内置规则之前,默认为空。最后是按常见约定写的内置规则:Jest、Vitest、`go test`、pytest、RSpec、XCTest 与 .NET 的测试目录和文件、快照、本地化目录与 lockfile 属于“测试”;包清单、类型声明、头文件、类型存根与 Protocol Buffers、GraphQL、OpenAPI 等接口定义属于“接口”。其余文件属于“实现”。例如在 `.gitattributes` 中写 `*_test.go dsh-review-layer=test` 或 `api/**/*.yaml dsh-review-layer=interface`,即可记录仓库自己的约定。“隐藏测试文件”让文件树与 diff 都不显示“测试”层,也不列出被隐藏的文件,同时停用“测试”透镜。文件标题上的“已审阅”把该文件的这次改动标为已审阅并折叠它;工具栏以按已审阅比例填充的圆环和“已审阅 2 / 3”这样的文字显示已显示文件中已审阅的数量,按 `V` 标记或取消当前阅读的文件:焦点或文本光标所在的文件,否则是视图顶部的文件。改动与标记时不同的文件显示“有新改动”并重新展开。只改文件模式(例如 `chmod +x`)也算新改动。变更请求的全部提交视图使用提供方保存在代码托管平台上的已审阅标记(GitHub 提供方即如此):视图随 diff 一起读取这些标记,勾选后立即显示,并在显示的 head 上保存,平台答复前该文件的复选框保持禁用;GitHub 报告为标记后又有改动的文件显示“有新改动”。平台拒绝或因新提交而过期的标记恢复原状,并以 toast 说明原因;平台可能已保存但未确认的标记保持不变,toast 提示刷新查看实际状态。无法读取标记时,提示条说明原因并提供“重试”,此时不能标记任何文件。悬停复选框会说明标记保存在哪里。其他标记按 Session、变更来源、路径与改动摘要保存在本浏览器中,关闭标签页或重新加载后仍在;同一 Session 的多个标签页共用这些标记:在一个标签页中标记,其他标签页随之更新,且不会覆盖它们的标记。“提交评审”左侧,以及“分支”范围中基准分支右侧的“全部提交”按从旧到新列出提交,读取一次后保留到 head、本地分支或基准变化或刷新为止;单击只看一个提交,按住 Shift 单击看从上次单击的提交到这个提交的连续多个提交,这些提交必须依次是后一个的第一父提交:离开这条链的范围(例如跨越已合并分支的范围)会让菜单保持打开并说明原因;此时视图显示这些提交的改动,在最后一个提交读取未变更的行,提供“添加到输入框”,但不提供 GitHub 评论或评审。“分支”的提交不含未提交与未跟踪的文件。换基准分支或范围后回到全部提交;所选提交已不存在或不再是一条链时提供“查看全部提交”。
- **评审讨论**——变更请求视图会叠加代码托管平台在所显示 head 处读到的评审讨论。行级讨论显示在它最后一行所在的行之后,位于写下时所在的那一侧;若该行折叠在未变更的行中,则显示在折叠行之后。讨论标明写下时的位置,每条评论显示头像、作者、时间和 Markdown 正文(不显示原始 HTML),并用标签标出变更请求作者、机器人账号,以及当前登录用户尚未提交的评审中的评论。已解决的讨论折叠成一行,可以展开。针对整个文件的讨论显示在文件开头;被后续提交改到而过期的讨论集中在文件的行之后,显示写下时那段 hunk 的末尾,并提供“查看当时的文件”,读取写下讨论时那个提交上的文件并标出相应的行。选择了部分提交时,只显示行号对应最后一个所选提交的新版本侧讨论。文件树和每个文件标题都显示未解决讨论数。每点击一次文件标题上的计数,就按文件中的显示顺序跳到该文件的下一条未解决讨论(所选提交中没有的讨论排在最后),到最后一条后回到第一条;工具栏的“讨论”按钮打开讨论列表。列表按文件树顺序分组,组内讨论的顺序与文件中相同,可显示未解决、已解决或全部讨论,默认显示未解决的讨论;点击讨论会跳到它的位置,若所选提交中没有该讨论,会先切换到全部提交。视图宽度不小于 1,040px 时列表停靠在文件旁;更窄时浮在文件之上,并在跳到讨论前先关闭;窄于 480px 时占满文件区的宽度。读取被截断时,列表会注明。讨论上提供“添加到输入框”(把整个讨论作为引用插入)、“在 GitHub 中查看”,以及当前登录用户可以执行的写操作。没有待提交评审时,回复框立即回复,其下拉菜单可以带着这条回复开始待提交评审;有待提交评审时,回复框把回复加入其中,因为 GitHub 会把用户的每条回复都加入待提交评审。“解决讨论”和“取消解决”切换讨论状态;用户自己评论的菜单可以编辑或删除该评论,删除前会先确认,删除讨论中唯一的评论会一并删除讨论,确认时会说明这一点。用户正在讨论中写回复或编辑评论时,即使讨论已被解决,也保持展开。代码托管平台拒绝写操作时保留输入的文字并说明原因;结果不明时会重新读取讨论,并请用户核对后再重试。每次写操作后都会重新读取讨论,因为解决讨论不会改变 GitHub pull request 的更新时间。视图显示期间,每收到一次状态就重新读取讨论;点击刷新后,即使面板还保留着之前的读取结果,也会从代码托管平台重新读取;读取失败时保留上次的讨论并提供重试,提供方不支持读取讨论时不显示讨论。
- **扩展 API**——其他插件通过[扩展 API](../../../docs/subsystems/forge.zh.md#extension-api)扩展变更视图。Host 插件用 `ctx.forgePanel.registerLens` 注册筛选透镜,Client 插件用 `ctx.forgeChanges.describeLens` 给它起名;工具栏随后在“隐藏测试文件”之后提供“透镜”菜单:只保留所选分层中被所选透镜保留的文件,透镜运行过之后显示它保留的文件数,并把被保留文件中透镜不关心的 hunk 折叠成一行,点开即显示。透镜运行时,菜单按钮显示进度;运行失败、被拒绝或中断时说明原因,并提供“重试”和“清除透镜”;透镜所在的插件卸载后停止筛选,并弹出提示。没有选透镜时,菜单与测试文件开关一起收进“更多”菜单。`ctx.forgeChanges` 还可以打开选定了文件和透镜的视图,并注册行注解数据源:注解放在其最后一行的评论和讨论之后、所在一侧的那一栏,整个文件的注解排在最前,写在较早改动上的注解排在最后,每个文件最多显示 `maxAnnotationsPerFile` 条。插件可以通过 `forge.changes.toolbar`、`forge.changes.file.menu`、`forge.diff.comment.actions` 与 `forge.change-request.card.actions` 这些 slot 添加工具栏工具(最先收进“更多”菜单)、文件菜单项、放在“添加到输入框”之后的评论框按钮,以及卡片头部按钮。
@@ -50,7 +50,7 @@ diff 按文件树的深度优先顺序排列:同层目录在前、文件在后
`gitCommand`、`gitTimeoutMs`、`graceMs`、`maxOutputBytes`、`readinessTimeoutMs`、`maxBranches`、`worktreePrefix`、`maxDiffBytes`、`maxUntrackedFiles`、`maxCachedDiffBytes`、`maxCachedReviewBytes`、`reviewRefreshMs`、`maxCommits`、`testPaths`、`interfacePaths`、`lensTimeoutMs`、`maxLensReadBytes`、`maxCachedLensBytes` 与 `maxAnnotationsPerFile` 列在[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-experimental-client-ui-forge)中。
“全部文件”打开可搜索的目录树,并把选中文件滚动到中间;只有一个子目录的路径会合并显示,重命名文件也可以按旧路径搜索。较宽的变更面板会在 diff 旁显示同一棵树,工具栏的“文件树”按钮按“左侧 → 右侧 → 隐藏”循环切换,默认显示在左侧。按钮的无障碍名称说明下一步操作,移动或隐藏文件树时焦点仍留在按钮上。移动或隐藏文件树,以及切换标签页与 Session 时保留搜索、折叠状态、选中文件和宽度。拖动分隔线,或聚焦分隔线后使用方向键,可以调整文件树宽度。文件与文件夹预留相同的展开箭头列,子项相对父目录向内缩进。本地变更与每个 PR 保留独立标签页。划选代码文字或通过行号选择同一已显示 hunk、同一侧的连续行,文字划选与复制都限定在起始侧。点击“+”打开纯文本评论框。使用鼠标时,悬停在某一行上也会在其行号旁显示“+”,行号仍可点击:两栏时显示在悬停的一侧,单栏时显示在该行所属的一侧;按下即选中这一行,拖动可在同一侧扩展范围,松开即打开评论框。可以同时打开多个评论框,再次选中已打开评论框的范围会回到该评论框。两栏时每条评论位于该行自己一侧的下方,左右两侧的评论并排处在同一行,各自延续所在行的底色。评论框支持换行和输入法组合输入,只有点击操作按钮才提交。可拖动底边调整高度。“添加到输入框”将评论作为可移除的引用加入主输入框,引用显示文件名、侧与行号以及评论,悬停时显示文件路径;多条引用只会在用户发送主输入框时一起发送。读到评审讨论且用户可以评审时,分段按钮会把这条评论加入用户在代码托管平台上的待提交评审,没有时先开始一个;评论随后显示为带“待提交”标签的讨论,提交评审之前只有用户自己能看到。下拉菜单可以立即发布单条评论;用户有待提交评审时没有该菜单。Agent 引用和已发布的评论保留在对应代码旁。“请求更改”需要填写评审总结,弹窗在总结输入框旁说明此要求,并在切换评审决定时播报。PR 标题栏中的“提交评审”打开居中弹窗,只显示待提交数量、总结以及“评论”“批准”“请求更改”选项。有待提交评审时提交该评审,结果不明的提交与直接提交一样,在用户到 GitHub 核对之前阻止再次提交;“丢弃评审”在确认后删除该评审及其中的评论;没有待提交评审时,把总结作为一次评审发布。代码托管平台不允许用户记录的结论不可用,例如在 GitHub 上用户自己的 PR 里,“批准”和“请求更改”不可用;只剩“评论”时,对话框会说明。视图中的文案按变更请求的提供方称呼代码托管平台及其对变更请求的叫法,例如 GitHub 和 PR。新建和删除文件只显示有内容的一侧行号。总结、评审决定,以及 Agent 引用与已发布评论的记录按 Session 和页签保存在当前浏览器,包括最初评审的 head。切换 Session 或隐藏面板时保留;关闭页签会清空它们,重新打开从空总结开始。待提交评审、已发布到 GitHub 的评论与已加入主输入框的引用不受影响。早期版本保存在此浏览器中的评论草稿保留在对应代码旁,带“浏览器草稿”标签,可以编辑、删除或加入待提交评审;存在待提交评审时,它们会让“提交评审”保持不可用;没有待提交评审时,“提交评审”把它们连同总结一起发布。head 变化后需要重新选择评论行。代码变化后的记录保留在文件末尾;文件已不在 diff 中时,记录显示在 diff 之后。页签保持打开时,结果不明的提交在重新加载后仍会阻止重复发送,直到用户检查 GitHub 并明确允许再次提交。
“全部文件”打开可搜索的目录树,并把选中文件滚动到中间;只有一个子目录的路径会合并显示,重命名文件也可以按旧路径搜索。较宽的变更面板会在 diff 旁显示同一棵树,工具栏的“文件树”按钮按“左侧 → 右侧 → 隐藏”循环切换,默认显示在左侧。按钮的无障碍名称说明下一步操作,移动或隐藏文件树时焦点仍留在按钮上。移动或隐藏文件树,以及切换标签页与 Session 时保留搜索、折叠状态、选中文件和宽度。拖动分隔线,或聚焦分隔线后使用方向键,可以调整文件树宽度;文件树至少保持上方透镜完整显示各层名称所需的宽度。文件与文件夹预留相同的展开箭头列,子项相对父目录向内缩进。本地变更与每个 PR 保留独立标签页。划选代码文字或通过行号选择同一已显示 hunk、同一侧的连续行,文字划选与复制都限定在起始侧。点击“+”打开纯文本评论框。使用鼠标时,悬停在某一行上也会在其行号旁显示“+”,行号仍可点击:两栏时显示在悬停的一侧,单栏时显示在该行所属的一侧;按下即选中这一行,拖动可在同一侧扩展范围,松开即打开评论框。可以同时打开多个评论框,再次选中已打开评论框的范围会回到该评论框。两栏时每条评论位于该行自己一侧的下方,左右两侧的评论并排处在同一行,各自延续所在行的底色。评论框支持换行和输入法组合输入,只有点击操作按钮才提交。可拖动底边调整高度。“添加到输入框”将评论作为可移除的引用加入主输入框,引用显示文件名、侧与行号以及评论,悬停时显示文件路径;多条引用只会在用户发送主输入框时一起发送。读到评审讨论且用户可以评审时,分段按钮会把这条评论加入用户在代码托管平台上的待提交评审,没有时先开始一个;评论随后显示为带“待提交”标签的讨论,提交评审之前只有用户自己能看到。下拉菜单可以立即发布单条评论;用户有待提交评审时没有该菜单。Agent 引用和已发布的评论保留在对应代码旁。“请求更改”需要填写评审总结,弹窗在总结输入框旁说明此要求,并在切换评审决定时播报。PR 标题栏中的“提交评审”打开居中弹窗,只显示待提交数量、总结以及“评论”“批准”“请求更改”选项。有待提交评审时提交该评审,结果不明的提交与直接提交一样,在用户到 GitHub 核对之前阻止再次提交;“丢弃评审”在确认后删除该评审及其中的评论;没有待提交评审时,把总结作为一次评审发布。代码托管平台不允许用户记录的结论不可用,例如在 GitHub 上用户自己的 PR 里,“批准”和“请求更改”不可用;只剩“评论”时,对话框会说明。视图中的文案按变更请求的提供方称呼代码托管平台及其对变更请求的叫法,例如 GitHub 和 PR。新建和删除文件只显示有内容的一侧行号。总结、评审决定,以及 Agent 引用与已发布评论的记录按 Session 和页签保存在当前浏览器,包括最初评审的 head。切换 Session 或隐藏面板时保留;关闭页签会清空它们,重新打开从空总结开始。待提交评审、已发布到 GitHub 的评论与已加入主输入框的引用不受影响。早期版本保存在此浏览器中的评论草稿保留在对应代码旁,带“浏览器草稿”标签,可以编辑、删除或加入待提交评审;存在待提交评审时,它们会让“提交评审”保持不可用;没有待提交评审时,“提交评审”把它们连同总结一起发布。head 变化后需要重新选择评论行。代码变化后的记录保留在文件末尾;文件已不在 diff 中时,记录显示在 diff 之后。页签保持打开时,结果不明的提交在重新加载后仍会阻止重复发送,直到用户检查 GitHub 并明确允许再次提交。
-----
@@ -619,6 +619,8 @@ export function ChangesTab({
const [treeState, setTreeState] = useState<ChangedFilesState>({ query: '', collapsed: {}, selected: null })
const [treePosition, setTreePosition] = useState<FileTreePosition>('left')
const [treeWidth, setTreeWidth] = useState(0)
// The lens's labels set the least width of the tree they sit above.
const [lensWidth, setLensWidth] = useState(0)
const treeId = useId()
const [chosen, setChosen] = useState<Readonly<Record<string, boolean>>>({})
// Each navigation applies once; its file, if it names one, opens and scrolls into view.
@@ -1321,7 +1323,7 @@ export function ChangesTab({
{!reviewOpen && reviewError !== null && reviewState.uncertain === null && <Notice>{reviewError}</Notice>}
<div className={css.toolbar} data-tree={treeShown ? treePosition : 'hidden'} style={toolbarStyle}>
{/* Above the file tree, the lens spans the tree's width; elsewhere a menu in the toolbar takes its place. */}
{treeShown && <div className={css.lensCell}><LensControl {...lensProps} /></div>}
{treeShown && <div className={css.lensCell}><LensControl {...lensProps} need={setLensWidth} /></div>}
<div ref={toolbarRow} className={css.toolbarMain}>
{tab.visible && source.kind === 'local' && <ScopeMenu scope={scope} choose={(next) => { actions.scoped(tab.id, next) }} t={t} />}
{tab.visible && <span className={css.filesSlot}><ChangedFilesMenu {...navigator} visible /></span>}
@@ -1429,7 +1431,9 @@ export function ChangesTab({
{reviewForm}
<div className={css.body}>
{body}
{allFiles.length > 0 && <FileTreePane {...navigator} id={treeId} position={treePosition} onWidth={setTreeWidth} />}
{allFiles.length > 0 && (
<FileTreePane {...navigator} id={treeId} position={treePosition} least={lensWidth} onWidth={setTreeWidth} />
)}
{review !== null && data?.kind === 'change' && threadList.open && (
<ThreadList entries={placed.entries} files={allFiles} truncated={review.truncated} url={data.url}
filter={threadList.filter} choose={(filter) => { setThreadList(value => ({ ...value, filter })) }}
@@ -15,12 +15,15 @@ export type FileTreePosition = 'right' | 'left' | 'hidden'
/**
* Render a keyboard- and pointer-resizable tree beside the diff.
* @param props - tree rows, pane position, the toggle's controlled element id, and the receiver of the shown width.
* @param props - tree rows, pane position, the toggle's controlled element id, the width the cell above the tree needs,
* and the receiver of the shown width.
* @returns the bounded pane and its resize separator.
*/
export function FileTreePane({ position, id, onWidth, ...props }: ChangedFilesProps & {
export function FileTreePane({ position, id, least = 0, onWidth, ...props }: ChangedFilesProps & {
readonly position: FileTreePosition
readonly id: string
/** Width in pixels the toolbar cell above the tree needs, which raises the pane's least width above its own. */
readonly least?: number
/** Receives the pane's width in pixels whenever it changes, so the toolbar can align a cell with it. */
readonly onWidth: (width: number) => void
}): ReactNode {
@@ -42,13 +45,15 @@ export function FileTreePane({ position, id, onWidth, ...props }: ChangedFilesPr
observer.observe(parent)
return () => { observer.disconnect() }
}, [])
const shown = Math.min(width, maximum)
const floor = Math.max(MIN_WIDTH, least)
const top = Math.max(floor, maximum)
const shown = Math.max(floor, Math.min(width, top))
useLayoutEffect(() => { onWidth(shown) }, [shown, onWidth])
const direction = position === 'left' ? 1 : -1
const resize = (next: number): void => { setWidth(Math.round(Math.max(MIN_WIDTH, Math.min(maximum, next)))) }
const resize = (next: number): void => { setWidth(Math.round(Math.max(floor, Math.min(top, next)))) }
return <div ref={pane} className={clsx(css.pane, changesCss.treePane)} data-position={position} hidden={position === 'hidden'} style={{ width: shown }}>
<div className={css.resize} role="separator" tabIndex={0} aria-label={props.t('diff.resizeFileTree')}
aria-orientation="vertical" aria-controls={id} aria-valuemin={MIN_WIDTH} aria-valuemax={maximum} aria-valuenow={shown}
aria-orientation="vertical" aria-controls={id} aria-valuemin={floor} aria-valuemax={top} aria-valuenow={shown}
onPointerDown={(event) => {
if (event.button !== 0) return
event.preventDefault()
@@ -70,7 +75,7 @@ export function FileTreePane({ position, id, onWidth, ...props }: ChangedFilesPr
onKeyDown={(event) => {
if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return
event.preventDefault()
resize(event.key === 'Home' ? MIN_WIDTH : event.key === 'End' ? maximum : shown + direction * (event.key === 'ArrowRight' ? 20 : -20))
resize(event.key === 'Home' ? floor : event.key === 'End' ? top : shown + direction * (event.key === 'ArrowRight' ? 20 : -20))
}} />
<nav id={id} className={css.navigation} aria-label={props.t('diff.allFiles', { count: props.files.length })}>
<ChangedFiles {...props} />
@@ -55,6 +55,45 @@
outline-offset: -2px;
}
/* Segments as wide as their labels, sharing what remains equally. */
.segmented[data-sizing='content'] {
display: flex;
}
.segmented[data-sizing='content'] > .segment {
flex: 1 1 auto;
}
/* The lens above the file tree with hidden copies that measure the width each form needs. */
.lensFit {
position: relative;
width: 100%;
min-width: 0;
}
.measures {
position: absolute;
top: 0;
left: 0;
visibility: hidden;
pointer-events: none;
}
.measures > div,
.measures .segmented {
width: max-content;
}
/* A count left out of view stays in the segment's accessible name. */
.hiddenCount {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
.segmentLabel {
min-width: 0;
overflow: hidden;
@@ -4,7 +4,7 @@
* share of shown files the reader marked viewed. The thread list shares the segmented radio group.
*/
import { useRef, useState, type KeyboardEvent, type ReactNode } from 'react'
import { useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from 'react'
import { IconChevronDownOutlineRegular, Menu, Switch, Tooltip, type MenuEntry } from '@deepseek-ai/dsh-client-ui-primitives'
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
import type { ChangesLens } from './changes-store.ts'
@@ -47,15 +47,19 @@ export interface Segment<Value extends string> {
/**
* Render a radio group whose segments share its width, each with a count after its label; arrow keys, Home, and End
* move between enabled segments.
* @param props - the segments, the chosen value, the choose action, and the group's localized accessible name.
* move between enabled segments. Segments are equally wide, or as wide as their labels with the rest shared equally.
* Without shown counts, a segment keeps its count in its accessible name and its hover text.
* @param props - the segments, the chosen value, the choose action, the group's localized accessible name, how segments
* size, and whether counts show.
* @returns the radio group.
*/
export function SegmentedChoice<Value extends string>({ segments, value, choose, label }: {
export function SegmentedChoice<Value extends string>({ segments, value, choose, label, sizing = 'equal', counted = true }: {
readonly segments: readonly Segment<Value>[]
readonly value: Value
readonly choose: (value: Value) => void
readonly label: string
readonly sizing?: 'equal' | 'content'
readonly counted?: boolean
}): ReactNode {
const group = useRef<HTMLDivElement>(null)
const enabled = segments.filter(segment => segment.disabledTip === null).map(segment => segment.value)
@@ -77,32 +81,82 @@ export function SegmentedChoice<Value extends string>({ segments, value, choose,
group.current?.querySelector<HTMLButtonElement>(`[data-segment="${next}"]`)?.focus()
}
return (
<div ref={group} role="radiogroup" aria-label={label} className={css.segmented}>
<div ref={group} role="radiogroup" aria-label={label} className={css.segmented} data-sizing={sizing}>
{segments.map((segment) => {
const button = (
<button key={segment.value} type="button" role="radio" className={css.segment} aria-checked={value === segment.value}
disabled={segment.disabledTip !== null} tabIndex={value === segment.value ? 0 : -1} data-segment={segment.value}
onKeyDown={move} onClick={() => { choose(segment.value) }}>
<span className={css.segmentLabel}>{segment.label}</span>
<span className={css.count}>{segment.count ?? ''}</span>
<span className={counted ? css.count : css.hiddenCount}>{segment.count ?? ''}</span>
</button>
)
return segment.disabledTip === null ? button : <Tooltip key={segment.value} label={segment.disabledTip} side="bottom">{button}</Tooltip>
const tip = segment.disabledTip ?? (counted || segment.count === null ? null : `${segment.label} ${String(segment.count)}`)
return tip === null ? button : <Tooltip key={segment.value} label={tip} side="bottom">{button}</Tooltip>
})}
</div>
)
}
/**
* Render the lens as a radio group whose segments share its width.
* @param props - the lens, its counts, whether test files hide, the choose action, and copy.
* @returns the radio group.
* Render the lens above the file tree as a radio group whose segments are as wide as their labels. Counts show while
* every segment fits whole beside its count; otherwise only labels show. The widths both forms need are measured on
* hidden copies whenever the cell, the labels, the counts, or the fonts change, and `need` receives the width of the
* cell that labels alone fill, which the file tree keeps as its least width.
* @param props - the lens, its counts, whether test files hide, the choose action, copy, and the receiver of the
* labels' width.
* @returns the radio group with its hidden measures.
*/
export function LensControl({ lens, counts, hideTests, choose, t }: LensProps): ReactNode {
export function LensControl({ lens, counts, hideTests, choose, t, need }: LensProps & {
/** Receives the cell width, padding included, at which the labels fit without counts. */
readonly need: (width: number) => void
}): ReactNode {
const root = useRef<HTMLDivElement>(null)
const withCounts = useRef<HTMLDivElement>(null)
const labelsOnly = useRef<HTMLDivElement>(null)
const [counted, setCounted] = useState(true)
// A disabled lens shows no count, since hidden test files are not counted.
return <SegmentedChoice label={t('lens.aria')} value={lens} choose={choose} segments={LENSES.map(item => item === 'test' && hideTests
const segments = LENSES.map((item): Segment<ChangesLens> => item === 'test' && hideTests
? { value: item, label: t(LENS_LABEL[item]), count: null, disabledTip: t('lens.testHidden') }
: { value: item, label: t(LENS_LABEL[item]), count: counts[item], disabledTip: null })} />
: { value: item, label: t(LENS_LABEL[item]), count: counts[item], disabledTip: null })
const key = JSON.stringify(segments.map(segment => [segment.label, segment.count]))
const needRef = useRef(need)
needRef.current = need
useLayoutEffect(() => {
const element = root.current
const full = withCounts.current
const bare = labelsOnly.current
const cell = element?.parentElement
/* v8 ignore next -- the refs are attached, inside a cell, before layout effects run */
if (element === null || full === null || bare === null || cell === null || cell === undefined) return
let live = true
// Fractional widths: a segment row a fraction of a pixel short of its labels still cuts every label short.
const width = (node: Element): number => node.getBoundingClientRect().width
const measure = (): void => {
const available = width(element)
// A hidden cell, such as one below the tree's breakpoint or in a hidden tab, has no width to compare.
if (!live || available === 0) return
setCounted(width(full) <= available)
needRef.current(Math.ceil(width(bare) + width(cell) - available))
}
measure()
const observer = new ResizeObserver(measure)
observer.observe(element)
const fonts = document.fonts
fonts.addEventListener('loadingdone', measure)
return () => {
live = false
observer.disconnect()
fonts.removeEventListener('loadingdone', measure)
}
}, [key])
return <div ref={root} className={css.lensFit}>
<SegmentedChoice label={t('lens.aria')} value={lens} choose={choose} segments={segments} sizing="content" counted={counted} />
<div className={css.measures} aria-hidden="true" {...{ inert: '' }}>
<div ref={withCounts}><SegmentedChoice label="" value={lens} choose={choose} segments={segments} sizing="content" /></div>
<div ref={labelsOnly}><SegmentedChoice label="" value={lens} choose={choose} segments={segments} sizing="content" counted={false} /></div>
</div>
</div>
}
/**
@@ -199,6 +199,19 @@ it('bounds pointer and keyboard resizing, retains hidden width, and stops cancel
} finally { vi.unstubAllGlobals() }
})
it('keeps the width the cell above the tree needs as its least width', () => {
vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(() => 1000)
const props = { files: [file('a.ts')], state: { query: '', collapsed: {}, selected: null }, t: makeTranslate(en), filter: vi.fn(), toggle: vi.fn(), jump: vi.fn(), id: 'tree', onWidth: vi.fn() }
const view = render(<FileTreePane {...props} position="left" least={276} />)
const handle = view.getByRole('separator')
expect([handle.getAttribute('aria-valuemin'), handle.getAttribute('aria-valuenow')]).toEqual(['276', '276'])
expect(props.onWidth).toHaveBeenLastCalledWith(276)
fireEvent.keyDown(handle, { key: 'Home' })
expect(handle.getAttribute('aria-valuenow')).toBe('276')
view.rerender(<FileTreePane {...props} position="left" least={150} />)
expect([handle.getAttribute('aria-valuemin'), handle.getAttribute('aria-valuenow')]).toEqual(['200', '276'])
})
it('can mount into a detached fragment without measuring a nonexistent parent element', () => {
const observe = vi.spyOn(ResizeObserver.prototype, 'observe')
const view = render(<FileTreePane files={[]} state={{ query: '', collapsed: {}, selected: null }} t={makeTranslate(en)}
@@ -1,13 +1,15 @@
// @vitest-environment jsdom
/** Review controls of the changes view: the lens in both forms, the test file switch, viewed progress, and the commit picker. */
import { act, cleanup, fireEvent, render, within } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, onTestFinished, vi } from 'vitest'
import { makeTranslate } from '@deepseek-ai/dsh-client-test-runtime'
import type { ForgeCommitList } from '@deepseek-ai/dsh-experimental-forge/types'
import { RemoteError, type RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
import { CommitMenu, commitsLabel, type CommitMenuProps } from '../src/client/CommitMenu.tsx'
import { en } from '../src/client/locales.ts'
import { HideTestsSwitch, LensControl, LensMenu, ViewedProgress, type LensProps } from '../src/client/ReviewControls.tsx'
import { HideTestsSwitch, LensControl, LensMenu, SegmentedChoice, ViewedProgress, type LensProps } from '../src/client/ReviewControls.tsx'
import css from '../src/client/ReviewControls.module.css'
import './fonts-dom.client.ts'
const t = makeTranslate(en)
const COUNTS = { all: 6, interface: 1, implementation: 2, test: 3 }
@@ -35,7 +37,7 @@ function lensProps(overrides: Partial<LensProps> = {}): LensProps & { readonly c
describe('LensControl', () => {
it('shows each lens with its count, chooses one by click, and walks enabled lenses by key', () => {
const props = lensProps({ lens: 'interface' })
const view = render(<LensControl {...props} />)
const view = render(<LensControl {...props} need={vi.fn()} />)
const radios = view.getAllByRole('radio')
expect(radios.map(radio => radio.textContent)).toEqual(['All6', 'Interface1', 'Implementation2', 'Tests3'])
expect(radios.map(radio => radio.getAttribute('aria-checked'))).toEqual(['false', 'true', 'false', 'false'])
@@ -56,7 +58,7 @@ describe('LensControl', () => {
it('moves focus with the selection and disables the test lens while test files hide', () => {
const props = lensProps({ lens: 'implementation', hideTests: true })
const view = render(<LensControl {...props} />)
const view = render(<LensControl {...props} need={vi.fn()} />)
const tests = view.getByRole('radio', { name: /^Tests/ })
expect((tests as HTMLButtonElement).disabled).toBe(true)
expect(tests.textContent).toBe('Tests')
@@ -70,6 +72,88 @@ describe('LensControl', () => {
})
})
describe('LensControl width', () => {
/** Render the lens in a cell with 8px padding on each side, the counted and bare forms measuring at the given widths. */
function fitted(widths: { cell: number; counted: number; labels: number }) {
let resized: () => void = () => {}
vi.stubGlobal('ResizeObserver', class {
constructor(callback: () => void) { resized = callback }
observe = vi.fn()
disconnect = vi.fn()
})
onTestFinished(() => { vi.unstubAllGlobals() })
const part = (element: HTMLElement): 'cell' | 'root' | 'counted' | 'labels' | null => {
if (element.dataset.cell !== undefined) return 'cell'
if (element.parentElement?.dataset.cell !== undefined) return 'root'
const measures = element.parentElement
if (measures?.getAttribute('aria-hidden') !== 'true') return null
return element === measures.firstElementChild ? 'counted' : 'labels'
}
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (this: HTMLElement) {
const role = part(this)
const width = role === 'cell' ? widths.cell : role === 'root' ? Math.max(0, widths.cell - 16)
: role === 'counted' ? widths.counted : role === 'labels' ? widths.labels : 0
return new DOMRect(0, 0, width, 28)
})
const need = vi.fn<(width: number) => void>()
const view = render(<div data-cell=""><LensControl {...lensProps({ lens: 'interface' })} need={need} /></div>)
const counts = (): (string | undefined)[] => view.getAllByRole('radio').map(radio => radio.lastElementChild?.className)
return { view, need, counts, widths, resize: (cell: number) => { widths.cell = cell; act(() => { resized() }) } }
}
it('shows the counts while they fit and the labels alone otherwise, keeping each count in its segment\'s name', () => {
const { view, need, counts, resize } = fitted({ cell: 300, counted: 280, labels: 200.25 })
expect(counts()).toEqual(Array(4).fill(css.count))
expect(need).toHaveBeenLastCalledWith(217)
resize(290)
expect(counts()).toEqual(Array(4).fill(css.hiddenCount))
expect(view.getByRole('radio', { name: 'Interface1' }).getAttribute('aria-checked')).toBe('true')
resize(296)
expect(counts()).toEqual(Array(4).fill(css.count))
})
it('measures again when fonts load, and stops once unmounted', () => {
const { view, need, counts, widths } = fitted({ cell: 300, counted: 280, labels: 200 })
widths.counted = 290
widths.labels = 230
act(() => { document.fonts.dispatchEvent(new Event('loadingdone')) })
expect(counts()).toEqual(Array(4).fill(css.hiddenCount))
expect(need).toHaveBeenLastCalledWith(246)
view.unmount()
need.mockClear()
document.fonts.dispatchEvent(new Event('loadingdone'))
expect(need).not.toHaveBeenCalled()
})
it('names a hidden count in the hover text of its segment, and nothing for a segment without a count', () => {
vi.useFakeTimers()
onTestFinished(() => { vi.useRealTimers() })
const view = render(<SegmentedChoice label="Filter" value="a" choose={vi.fn()} counted={false} segments={[
{ value: 'a', label: 'Open', count: null, disabledTip: null },
{ value: 'b', label: 'Done', count: 2, disabledTip: null },
]} />)
const hover = (name: RegExp): string | null => {
const radio = view.getByRole('radio', { name })
fireEvent.pointerEnter(radio)
act(() => { vi.advanceTimersByTime(1000) })
const text = within(document.body).queryByRole('tooltip')?.textContent ?? null
fireEvent.pointerLeave(radio)
act(() => { vi.advanceTimersByTime(1000) })
return text
}
expect(hover(/^Done/)).toBe('Done 2')
expect(hover(/^Open/)).toBeNull()
})
it('leaves the form as it is while the cell has no width', () => {
const { counts, need, resize } = fitted({ cell: 0, counted: 280, labels: 200 })
expect(counts()).toEqual(Array(4).fill(css.count))
expect(need).not.toHaveBeenCalled()
resize(0)
expect(need).not.toHaveBeenCalled()
})
})
describe('LensMenu', () => {
it('names the lens on its trigger and chooses another from its menu', () => {
const props = lensProps({ lens: 'test' })