fix(search): scope Find in Files to the focused folder (#534)

Find in Files from the keyboard ignored the selected folder and reused the saved scope; only the context menu passed a directory.

Focused trees now publish the selected folder, or a file's parent, as an action context, and Find and Replace in Files use it when no explicit directory is given. This covers the Project view, Commit and Changes, Bookmarks and Scratches. Group rows and editor focus keep the previous behaviour.

Fixes #526
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-10-31 12:43:42 +08:00
1 джерело a553dafa7a
коміт c5cb217c7c
11 files changed
+352 -9

No files matched your search

+2
Переглянути файл
@@ -7,6 +7,7 @@ import { useCallback, useEffect, useMemo, useRef, useState, type MouseEvent, typ
import { tx } from "@/platform/i18n";
import clsx from "clsx";
import { executeAction } from "@/platform/actions";
import { dirname } from "@/platform/project";
import {
Button,
Checkbox,
@@ -481,6 +482,7 @@ export function ChangesTree({ mode }: { mode: "commit" | "local" | "dialog" }) {
roots={roots}
getKey={(n) => n.key}
getLabel={nodeText}
getDirectory={(n) => (n.path && n.type !== "group" ? (n.type === "dir" ? n.path : dirname(n.path)) : null)}
getChildren={(n) => n.children}
isExpandable={(n) => n.type !== "file"}
expanded={expanded}
+45
Переглянути файл
@@ -0,0 +1,45 @@
import { beforeEach, describe, expect, it } from "vitest";
import { fireEvent, render, screen } from "@testing-library/react";
import { getContext } from "@/platform/context";
import { ChangesTree } from "../CommitView";
import { useCommit } from "../commitStore";
import { useVcs } from "../store";
beforeEach(() => {
useVcs.setState({
root: "/p",
roots: ["/p"],
status: [
{
path: "/p/documents/note.txt",
relPath: "documents/note.txt",
staged: null,
unstaged: "modified",
renamedFrom: null,
},
],
});
useCommit.setState({ groupByDir: true, checks: new Map(), selection: [] });
});
describe.each(["commit", "local", "dialog"] as const)("%s change tree directory", (mode) => {
it("scopes folders and file parents, and clears on groups and message focus", () => {
render(
<>
<ChangesTree mode={mode} />
<textarea aria-label="Commit message" />
</>,
);
const tree = screen.getByRole("tree", { name: "Changes" });
tree.focus();
fireEvent.keyDown(tree, { key: "Home" });
expect(getContext().focusedDirectory).toBeUndefined();
fireEvent.keyDown(tree, { key: "ArrowDown" });
expect(getContext().focusedDirectory).toBe("/p/documents");
fireEvent.keyDown(tree, { key: "ArrowRight" });
fireEvent.keyDown(tree, { key: "ArrowDown" });
expect(getContext().focusedDirectory).toBe("/p/documents");
screen.getByLabelText("Commit message").focus();
expect(getContext().focusedDirectory).toBeUndefined();
});
});