Compare commits

...
7 changed files with 109 additions and 36 deletions

No files matched your search

+37
View File
@@ -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);
});
+35 -14
View File
@@ -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;
+2 -2
View File
@@ -29,7 +29,7 @@ describe("TodoView", () => {
render(<TodoView />);
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(<TodoView />);
// 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
+32 -18
View File
@@ -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 (
<span className={styles.text} style={{ color }}>
<strong className={styles.keyword}>{item.text.slice(0, kwLen)}</strong>
<span className={styles.text}>
<strong className={styles.keyword} style={{ color }}>
{item.text.slice(0, kwLen)}
</strong>
{item.text.slice(kwLen)}
</span>
);
}
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 (
<>
<Toolbar aria-label="TODO actions" orientation="vertical" className={styles.toolbar}>
<IconButton icon="arrow-up" action="navigate.prevOccurrence" size="small" />
<IconButton icon="arrow-down" action="navigate.nextOccurrence" size="small" />
<IconButton
@@ -335,7 +338,7 @@ export function TodoHeaderActions() {
onClick={() => updateTodoSettings({ caseSensitive: !settings.caseSensitive })}
/>
<IconButton icon="refresh" size="small" title="Refresh" disabled={scanning} onClick={() => void scanProject()} />
</>
</Toolbar>
);
}
@@ -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 (
<span className={styles.row}>
<Icon name={fileIconName(name)} size={16} className={styles.fileIcon} />
<span className={clsx(styles.fileName, state.selected && styles.selectedText)}>{name}</span>
<span className={styles.muted}>{relativeDir(root, n.group.path)}</span>
<span className={styles.fileLocation}>
<span className={clsx(styles.fileName, state.selected && styles.selectedText)} title={name}>
{name}
</span>
{directory && (
<span className={styles.directory} title={directory}>
{directory}
</span>
)}
</span>
<span className={styles.count}>
{n.group.items.length === 1 ? tx`${n.group.items.length} item` : tx`${n.group.items.length} items`}
</span>
@@ -434,8 +446,8 @@ export function TodoView() {
}
return (
<span className={styles.row} title={n.item.text}>
<span className={styles.position}>
({n.item.line + 1}, {n.item.col + 1})
<span className={styles.position} title={`(${n.item.line + 1}, ${n.item.col + 1})`}>
{n.item.line + 1}
</span>
<ItemText item={n.item} />
</span>
@@ -469,18 +481,20 @@ export function TodoView() {
return (
<div className={styles.view}>
{tab === "project" && limitHit && (
<div className={styles.banner}>
<T>Too many matches; showing the first 10 000.</T>
</div>
)}
{tab === "scope" && <ScopeBar />}
{tab === "changes" && <ChangelistBar />}
<div className={styles.body}>
<TodoToolbar />
<div className={styles.content}>
{tab === "project" && limitHit && (
<div className={styles.banner}>
<T>Too many matches; showing the first 10 000.</T>
</div>
)}
{tab === "scope" && <ScopeBar />}
{tab === "changes" && <ChangelistBar />}
<SplitGroup
orientation="horizontal"
id="todo-preview-split"
storageKey={showPreview ? "openidea.todo.previewSplit" : undefined}
className={styles.body}
>
<SplitPanel id="items" minSize={160} className={styles.panel}>
<Tree<Node>
@@ -519,7 +533,7 @@ export function TodoView() {
{showPreview && (
<>
<SplitHandle />
<SplitPanel id="preview" minSize={160} defaultSize="45%" className={styles.panel}>
<SplitPanel id="preview" minSize={160} defaultSize="50%" className={styles.panel}>
<TodoPreview node={lead} />
</SplitPanel>
</>
+1 -2
View File
@@ -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,
}),
+1
View File
@@ -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",
+1
View File
@@ -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 项不可用",