feat: hide dotfiles in file explorer (#1516)
* feat: hide dotfiles in file explorer * refactor: rename to "hidden files" and read flag from store Rename the explorer dotfile toggle to show-semantics "hidden files" so copy and code share one cross-platform vocabulary, and stop prop-drilling the flag now that it lives in the panel store. - explorerShowHiddenFiles (default true) replaces explorerHideDotFiles; i18n keys + translations switched from "dotfiles" to "hidden files" - imperative helpers read usePanelStore.getState() instead of taking the flag as a parameter; flag stays threaded only through the reactive tree-row render path - drop dead usePanelState exposure; collapse migration double-guard * fix: address Greptile review on hidden-file path matching - isHiddenExplorerPath no longer treats ".." segments as hidden (only "." was exempt before); add tests for ".." and "../sibling" - assert the showHiddenFiles i18n key alongside hideHiddenFiles --------- Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
This commit is contained in:
co-authored by
Mohamed Boudra
parent
f4450cda51
commit
eb94b70848
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ExplorerEntry } from "@/stores/session-store";
|
||||
import { filterVisibleExplorerEntries, isHiddenExplorerPath } from "./visibility";
|
||||
|
||||
function makeEntry(name: string, kind: ExplorerEntry["kind"]): ExplorerEntry {
|
||||
return {
|
||||
name,
|
||||
path: name,
|
||||
kind,
|
||||
size: 0,
|
||||
modifiedAt: "2026-01-01T00:00:00.000Z",
|
||||
};
|
||||
}
|
||||
|
||||
describe("file explorer visibility", () => {
|
||||
it("keeps dot-prefixed entries when hidden files are shown", () => {
|
||||
const entries = [makeEntry(".env", "file"), makeEntry("src", "directory")];
|
||||
|
||||
expect(filterVisibleExplorerEntries(entries, true)).toEqual(entries);
|
||||
});
|
||||
|
||||
it("hides dot-prefixed files and directories when hidden files are not shown", () => {
|
||||
const entries = [
|
||||
makeEntry(".env", "file"),
|
||||
makeEntry(".git", "directory"),
|
||||
makeEntry("README.md", "file"),
|
||||
makeEntry("src", "directory"),
|
||||
];
|
||||
|
||||
expect(filterVisibleExplorerEntries(entries, false).map((entry) => entry.name)).toEqual([
|
||||
"README.md",
|
||||
"src",
|
||||
]);
|
||||
});
|
||||
|
||||
it("detects paths nested under dot-prefixed directories", () => {
|
||||
expect(isHiddenExplorerPath(".")).toBe(false);
|
||||
expect(isHiddenExplorerPath("..")).toBe(false);
|
||||
expect(isHiddenExplorerPath("../sibling")).toBe(false);
|
||||
expect(isHiddenExplorerPath("src/components")).toBe(false);
|
||||
expect(isHiddenExplorerPath(".git")).toBe(true);
|
||||
expect(isHiddenExplorerPath("src/.cache/output.json")).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { ExplorerEntry } from "@/stores/session-store";
|
||||
|
||||
export function isHiddenExplorerPath(path: string): boolean {
|
||||
return path
|
||||
.split("/")
|
||||
.some((segment) => segment !== "." && segment !== ".." && segment.startsWith("."));
|
||||
}
|
||||
|
||||
export function filterVisibleExplorerEntries(
|
||||
entries: ExplorerEntry[],
|
||||
showHiddenFiles: boolean,
|
||||
): ExplorerEntry[] {
|
||||
if (showHiddenFiles) {
|
||||
return entries;
|
||||
}
|
||||
return entries.filter((entry) => !entry.name.startsWith("."));
|
||||
}
|
||||
Reference in New Issue
Block a user