Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 416697bd57 fix(project-tree): explain when filters hide a requested file 2026-11-18 19:11:06 +08:00
7 змінених файлів з 118 додано та 15 видалено

No files matched your search

+53 -1
Переглянути файл
@@ -7,6 +7,7 @@ import { applyKeymapSettings, installKeyboardDispatcher, useKeymap } from "@/pla
import { usePlatform } from "@/platform/platformInfo";
import {
provideEditorService,
provideNotificationService,
registerProjectViewRoot,
setFileDecorations,
type EditorService,
@@ -290,16 +291,67 @@ describe("ProjectView", () => {
await waitFor(() => expect(selected()).toEqual(["README.md"]));
focusEditor("/w/acme/src/App.kt");
await waitFor(() => expect(selected()).toEqual(["App.kt"]));
act(() => setViewOption("showExcluded", false));
focusEditor("/w/acme/build/out.class");
await waitFor(() => expect(useProjectTree.getState().revealRequest).toBeNull());
expect(selected()).toEqual(["App.kt"]);
act(() => setViewOption("autoscrollFromSource", false));
focusEditor("/w/acme/README.md");
expect(selected()).toEqual(["App.kt"]);
expect(screen.getByRole("button", { name: "Select Opened File" })).toBeTruthy();
} finally {
act(() => useEditorRegistry.setState({ active: null }));
act(() => {
useEditorRegistry.setState({ active: null });
setViewOption("autoscrollFromSource", false);
setViewOption("showExcluded", true);
});
}
});
it.each([
["showExcluded", "build/out.class", "Show Excluded Files"],
["showHidden", "src/generated.pyc", "Show Hidden Files"],
] as const)(
"explains a file hidden by %s and leaves the tree selection and filter alone",
async (option, relative, label) => {
const path = `${ROOT}/${relative}`;
if (!fs.nodes.has(path)) await fs.createFile(path);
const notify = vi.fn();
provideNotificationService({ notify });
provideEditorService({ openFile, activePath: () => path } as unknown as EditorService);
setContext("projectOpen", true);
setViewOption(option, false);
try {
const { row, rows } = setup();
render(<ProjectHeaderActions />);
const locate = screen.getByRole("button", { name: "Select Opened File" });
await waitFor(() => expect(rows()).toContain("README.md"));
fireEvent.mouseDown(row("README.md"));
fireEvent.click(locate);
await waitFor(() =>
expect(notify).toHaveBeenCalledWith(
expect.objectContaining({
title: "Hidden in Project View",
body: `Turn on ${label} in the Project view's Options to locate it.`,
}),
),
);
expect(row("README.md")).toHaveAttribute("aria-selected", "true");
expect(useProjectTree.getState().options[option]).toBe(false);
act(() => setViewOption(option, true));
fireEvent.click(locate);
const name = relative.split("/").at(-1)!;
await waitFor(() => expect(row(name)).toHaveAttribute("aria-selected", "true"));
expect(notify).toHaveBeenCalledTimes(1);
} finally {
act(() => setViewOption(option, option === "showExcluded"));
setContext("projectOpen", false);
}
},
);
it("expands and collapses folders on single click only when enabled", async () => {
const { row, rows } = setup();
await waitFor(() => expect(rows()).toContain("README.md"));
+9 -3
Переглянути файл
@@ -86,6 +86,7 @@ import {
VIEW_MODES,
autoExpand,
clearRevealRequest,
hiddenRevealOption,
loadDir,
loadOutline,
revealPath,
@@ -517,12 +518,17 @@ export function ProjectView() {
// Select a revealed path once its row exists.
useEffect(() => {
if (!revealRequest) return;
const { path, focus, seq } = revealRequest;
const { path, root, focus, seq, onHidden } = revealRequest;
const exact = model.keyOfPath.get(path);
const hidden = exact ? null : hiddenRevealOption(root, path);
const loadingAncestors = info.pending.some((p) => p === path || isInside(path, p));
if (!exact && loadingAncestors) return;
const key = exact ?? nodeKeyFor(model, path);
if (!exact && !hidden && loadingAncestors) return;
clearRevealRequest(seq);
if (hidden) {
onHidden?.(hidden);
return;
}
const key = exact ?? nodeKeyFor(model, path);
if (!key || !info.visible.has(key)) return;
revealing.current = true;
handle.current?.reveal(key);
+14 -3
Переглянути файл
@@ -5,11 +5,11 @@ import { getContext } from "@/platform/context";
import { canRevealInFileManager, revealInFileManagerLabel } from "@/platform/fileManager";
import { dirname, useProject } from "@/platform/project";
import { showContextMenu, type MenuItem } from "@/ui";
import { maybeEditorService, menuGroupItems, toolWindowService } from "@/workbench/contributions";
import { maybeEditorService, menuGroupItems, notifications, toolWindowService } from "@/workbench/contributions";
import { OPTION_LABELS, SORT_LABELS } from "./HeaderActions";
import { compareTarget, newMenuItems, revealLabel } from "./contextMenu";
import { openNewPopup } from "./newPopupModel";
import type { ProjectNode } from "./model";
import type { FileVisibilityOption, ProjectNode } from "./model";
import {
beginNew,
beginRename,
@@ -102,13 +102,24 @@ function showProjectView(focus: boolean) {
}
}
function explainHiddenFile(option: FileVisibilityOption) {
const [, label] = OPTION_LABELS.find(([key]) => key === option)!;
notifications().notify({
level: "info",
key: "project.hiddenFile",
title: "Hidden in Project View",
body: tx`Turn on ${label} in the Project view's Options to locate it.`,
userInitiated: true,
});
}
/** Selects `path` (default: the active editor's file) in the project view. */
export function selectInProjectView(path?: string | null, focus = true) {
const target = path ?? maybeEditorService()?.activePath() ?? null;
if (!target) return false;
if (!modeShows(target)) setViewMode("project");
showProjectView(focus);
return revealPath(target, focus);
return revealPath(target, focus, focus ? explainHiddenFile : undefined);
}
/**
+9 -5
Переглянути файл
@@ -90,12 +90,16 @@ export function unityPathVisible(path: string, opts: TreeOptions): boolean {
return true;
}
export function isVisible(entry: FileEntry, opts: TreeOptions): boolean {
if (!unityPathVisible(entry.path, opts)) return false;
export type FileVisibilityOption = "showHidden" | "showExcluded";
export function hiddenByFileOption(entry: FileEntry, opts: TreeOptions): FileVisibilityOption | null {
// Ignored names are also excluded on the backend; only "Show Hidden" brings them back.
if (isIgnoredName(entry.name)) return opts.showHidden;
if (!opts.showExcluded && entry.ignored) return false;
return true;
if (isIgnoredName(entry.name)) return opts.showHidden ? null : "showHidden";
return !opts.showExcluded && entry.ignored ? "showExcluded" : null;
}
export function isVisible(entry: FileEntry, opts: TreeOptions): boolean {
return unityPathVisible(entry.path, opts) && hiddenByFileOption(entry, opts) === null;
}
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
+29 -3
Переглянути файл
@@ -25,11 +25,13 @@ import {
withExtraRoots,
withReadOnlyFolders,
dropListings,
hiddenByFileOption,
isDirEntry,
mergeListing,
planRefresh,
visibleEntries,
unityPathVisible,
type FileVisibilityOption,
type Placeholder,
type ProjectNode,
type TreeModel,
@@ -108,6 +110,14 @@ export interface Clipboard {
osWrite?: Promise<boolean>;
}
interface RevealRequest {
path: string;
root: string;
focus: boolean;
seq: number;
onHidden?: (option: FileVisibilityOption) => void;
}
interface ProjectTreeState {
unity: UnityProjectInfo | null;
root: string | null;
@@ -122,7 +132,7 @@ interface ProjectTreeState {
editing: Editing | null;
clipboard: Clipboard | null;
/** A path to select (and scroll to) once its row is visible. */
revealRequest: { path: string; focus: boolean; seq: number } | null;
revealRequest: RevealRequest | null;
/** Folder key highlighted as drop target. */
dropTarget: string | null;
mode: ViewMode;
@@ -635,7 +645,7 @@ export function dropOutlines(paths: readonly string[]) {
let revealSeq = 0;
/** Expands the ancestors of `path` and selects it once visible. */
export function revealPath(requested: string, focus = false) {
export function revealPath(requested: string, focus = false, onHidden?: RevealRequest["onHidden"]) {
const { expanded } = get();
const project = get().root;
if (!project) return false;
@@ -668,11 +678,27 @@ export function revealPath(requested: string, focus = false) {
changed = true;
}
if (changed) setExpanded(next);
set({ revealRequest: { path, focus, seq: ++revealSeq } });
set({ revealRequest: { path, root, focus, seq: ++revealSeq, onHidden } });
for (const a of folders) void loadDir(a);
return true;
}
/** The first hidden entry on a reveal's path may be one of its folders. */
export function hiddenRevealOption(root: string, path: string): FileVisibilityOption | null {
const state = get();
if (isFilteredMode(state.mode)) return null;
const options = treeOptions(state);
const folders = ancestorsWithin(root, path);
for (const [i, folder] of folders.entries()) {
const child = folders[i + 1] ?? path;
const entry = state.listings.get(folder)?.find((file) => file.path === child);
if (!entry) return null;
const option = hiddenByFileOption(entry, options);
if (option) return option;
}
return null;
}
/**
* The linked workspace project containing `path`, if any (the innermost one). A
* workspace's root is its own directory; its projects are separate top-level roots.
+2
Переглянути файл
@@ -150,6 +150,8 @@
"Issue link": "Issue link",
"Subject": "Subject",
"Project View": "Project View",
"Hidden in Project View": "Hidden in Project View",
"Turn on {option} in the Project view's Options to locate it.": "Turn on {option} in the Project view's Options to locate it.",
"Changed decoration": "Changed decoration",
"HEAD tags decoration": "HEAD tags decoration",
"Local branch decoration": "Local branch decoration",
+2
Переглянути файл
@@ -4651,6 +4651,8 @@
"Show Hidden Files": "显示隐藏文件",
"Show Members": "显示成员",
"Show Excluded Files": "显示已排除的文件",
"Hidden in Project View": "项目视图中已隐藏",
"Turn on {option} in the Project view's Options to locate it.": "在项目视图的“选项”中开启“{option}”即可定位。",
"Compact Middle Packages": "压缩中间软件包",
"Sort Folders First": "文件夹排在前面",
"Open Files with Single Click": "单击打开文件",