From 821b4e8e0106938fb4ca37ebe1d834cbfec79ad0 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:38:45 +0800 Subject: [PATCH] fix(todo): improve tool window layout and result typography --- e2e/todo-layout.spec.ts | 37 ++++++++++++++++++++ src/features/todo/TodoView.module.css | 49 ++++++++++++++++++-------- src/features/todo/TodoView.test.tsx | 4 +-- src/features/todo/TodoView.tsx | 50 +++++++++++++++++---------- src/features/todo/index.ts | 3 +- src/platform/locales/text/en.json | 1 + src/platform/locales/text/zh.json | 1 + 7 files changed, 109 insertions(+), 36 deletions(-) create mode 100644 e2e/todo-layout.spec.ts diff --git a/e2e/todo-layout.spec.ts b/e2e/todo-layout.spec.ts new file mode 100644 index 0000000000..83cafcd0d3 --- /dev/null +++ b/e2e/todo-layout.spec.ts @@ -0,0 +1,37 @@ +import { expect, test } from "./fixtures"; + +test("keeps the file count visible beside a long directory in the TODO pane", async ({ workbench: page }) => { + await page.setViewportSize({ width: 900, height: 760 }); + await page.evaluate(async () => { + const projectModule = "/src/platform/project.ts"; + const todoModule = "/src/features/todo/store.ts"; + const { useProject } = await import(/* @vite-ignore */ projectModule); + const { useTodos } = await import(/* @vite-ignore */ todoModule); + const directory = "src/features/checkout/shared/services/with-a-long-directory-name/for-order-processing"; + const path = `${useProject.getState().project.root}/${directory}/orders.ts`; + useTodos.setState({ + scannedOnce: true, + error: null, + scanned: new Map([[path, [{ path, line: 8, col: 3, keyword: "TODO", text: "TODO: validate orders" }]]]), + }); + }); + + await page.getByRole("button", { name: "TODO" }).click(); + const pane = page.locator('[data-toolwindow="todo"]'); + const toolbar = pane.getByRole("toolbar", { name: "TODO actions" }); + await expect(toolbar).toHaveAttribute("aria-orientation", "vertical"); + const tree = pane.getByRole("tree", { name: "TODO items" }); + const fileName = tree.getByText("orders.ts", { exact: true }); + await expect(fileName).toBeVisible(); + await expect.poll(() => fileName.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true); + const count = tree.getByText("1 item", { exact: true }); + await expect(count).toBeVisible(); + await expect + .poll(() => + count.evaluate( + (element) => + element.getBoundingClientRect().right <= element.closest('[role="tree"]')!.getBoundingClientRect().right, + ), + ) + .toBe(true); +}); diff --git a/src/features/todo/TodoView.module.css b/src/features/todo/TodoView.module.css index 9d4d3552a5..a6582a12d8 100644 --- a/src/features/todo/TodoView.module.css +++ b/src/features/todo/TodoView.module.css @@ -1,16 +1,25 @@ .view { height: 100%; display: flex; - flex-direction: column; min-height: 0; } -.body { +.toolbar { + flex: none; + display: flex; + flex-direction: column; + gap: var(--space-1); + padding: var(--space-1); + border-inline-end: 1px solid var(--border); + overflow-y: auto; +} +.content { flex: 1; + min-width: 0; min-height: 0; display: flex; flex-direction: column; } -.body > * { +.body { flex: 1; min-height: 0; } @@ -37,13 +46,12 @@ display: flex; align-items: center; gap: var(--space-1-5); - height: 32px; - padding: 0 8px; + padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--border); } .scopeSelect { - min-width: 200px; - max-width: 360px; + flex: 0 1 224px; + min-width: 0; } .row { display: flex; @@ -57,7 +65,17 @@ flex: none; color: var(--fg-muted); } +.fileLocation { + display: flex; + gap: var(--space-1-5); + min-width: 0; + overflow: hidden; +} .fileName { + flex: none; + max-inline-size: 100%; + overflow: hidden; + text-overflow: ellipsis; color: var(--fg-emphasis); } .selectedText { @@ -66,28 +84,31 @@ .muted { flex: none; color: var(--fg-subtle); - font-size: var(--fs-small); +} +.directory { + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + color: var(--fg-subtle); } .count { + flex: none; color: var(--fg-subtle); - font-size: var(--fs-small); - margin-left: 4px; } .position { flex: none; - font-family: var(--font-mono); - font-size: var(--fs-small); + min-inline-size: 3ch; + text-align: end; + font-variant-numeric: tabular-nums; color: var(--fg-subtle); } .text { min-width: 0; overflow: hidden; text-overflow: ellipsis; - font-style: italic; } .keyword { font-weight: 600; - font-style: normal; } .loading { display: flex; diff --git a/src/features/todo/TodoView.test.tsx b/src/features/todo/TodoView.test.tsx index 9be249e6e8..7843a5d81a 100644 --- a/src/features/todo/TodoView.test.tsx +++ b/src/features/todo/TodoView.test.tsx @@ -29,7 +29,7 @@ describe("TodoView", () => { render(); expect(screen.getByText("a.ts")).toBeInTheDocument(); expect(screen.getByText("2 items")).toBeInTheDocument(); - expect(screen.getByText("(5, 4)")).toBeInTheDocument(); + expect(screen.getByText("5")).toHaveAttribute("title", "(5, 4)"); expect(screen.getByText(": wire it")).toBeInTheDocument(); act(() => useTodoView.getState().toggleKeyword("FIXME")); expect(screen.getByText("1 item")).toBeInTheDocument(); @@ -135,7 +135,7 @@ describe("TodoView", () => { render(); // Select the file group so the preview has an item (trees select on mousedown). fireEvent.mouseDown(screen.getByText("a.ts").closest("[role=treeitem]")!); - await screen.findByText("(5, 4)"); + await screen.findByText("5"); // No editing switch: the preview is simply an editor, like IntelliJ's. expect(screen.queryByLabelText("Allow editing")).toBeNull(); // No document attacher in tests: the editable pane degrades to its error diff --git a/src/features/todo/TodoView.tsx b/src/features/todo/TodoView.tsx index 280c9bab7d..719c2b54a1 100644 --- a/src/features/todo/TodoView.tsx +++ b/src/features/todo/TodoView.tsx @@ -19,6 +19,7 @@ import { SplitPanel, Spinner, Tabs, + Toolbar, Tree, fileIconName, type MenuItem, @@ -291,14 +292,16 @@ function ItemText({ item }: { item: TodoItem }) { const kwLen = item.keyword.length; const color = colorFor(item.keyword); return ( - - {item.text.slice(0, kwLen)} + + + {item.text.slice(0, kwLen)} + {item.text.slice(kwLen)} ); } -export function TodoHeaderActions() { +function TodoToolbar() { const settings = useTodoSettings(); const hidden = useTodoView((s) => s.hidden); const toggleKeyword = useTodoView((s) => s.toggleKeyword); @@ -316,7 +319,7 @@ export function TodoHeaderActions() { })), ]; return ( - <> + updateTodoSettings({ caseSensitive: !settings.caseSensitive })} /> void scanProject()} /> - + ); } @@ -421,11 +424,20 @@ export function TodoView() { const renderNode = (n: Node, state: TreeRowState) => { if (n.kind === "file") { const name = basename(n.group.path); + const directory = relativeDir(root, n.group.path); return ( - {name} - {relativeDir(root, n.group.path)} + + + {name} + + {directory && ( + + {directory} + + )} + {n.group.items.length === 1 ? tx`${n.group.items.length} item` : tx`${n.group.items.length} items`} @@ -434,8 +446,8 @@ export function TodoView() { } return ( - - ({n.item.line + 1}, {n.item.col + 1}) + + {n.item.line + 1} @@ -469,18 +481,20 @@ export function TodoView() { return (
- {tab === "project" && limitHit && ( -
- Too many matches; showing the first 10 000. -
- )} - {tab === "scope" && } - {tab === "changes" && } -
+ +
+ {tab === "project" && limitHit && ( +
+ Too many matches; showing the first 10 000. +
+ )} + {tab === "scope" && } + {tab === "changes" && } @@ -519,7 +533,7 @@ export function TodoView() { {showPreview && ( <> - + diff --git a/src/features/todo/index.ts b/src/features/todo/index.ts index 3b05403a93..a5681b58d4 100644 --- a/src/features/todo/index.ts +++ b/src/features/todo/index.ts @@ -4,7 +4,7 @@ import { registerEditorContribution } from "@/editor/api"; import { registerToolWindow, toolWindowService } from "@/workbench/contributions"; import { hasIcon } from "@/ui"; import { activateSettingsPages } from "./settingsPages"; -import { TodoHeaderActions, TodoTabs, TodoView, useTodoBadge, useTodoHeaderMenu, useTodoView } from "./TodoView"; +import { TodoTabs, TodoView, useTodoBadge, useTodoHeaderMenu, useTodoView } from "./TodoView"; import { todoEditorExtension } from "./highlight"; import { installTodoIndex, scanProject, syncTodoSettingsFromStorage } from "./store"; @@ -21,7 +21,6 @@ export function activate(): () => void { order: 40, component: TodoView, headerContent: TodoTabs, - headerActions: TodoHeaderActions, headerMenu: useTodoHeaderMenu, useBadge: useTodoBadge, }), diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 7f94d295b6..094437e1aa 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -1,4 +1,5 @@ { + "TODO actions": "TODO actions", "Same as the existing configuration '{existing}'": "Same as the existing configuration '{existing}'", "Windows file and folder names cannot end with a period or space": "Windows file and folder names cannot end with a period or space", "Use URL template": "Use URL template", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 68fa7c3357..73b09b4121 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -2944,6 +2944,7 @@ "System-Dependent": "取决于系统", "Tests failed: {detail}": "测试失败:{detail}", "TODO comment": "TODO 注释", + "TODO actions": "TODO 操作", "TODO filters": "TODO 筛选器", "TODO items": "TODO 项", "TODO items unavailable": "TODO 项不可用",