Skip to content

Your lightweight open-source personal agent.

fix(webui): preserve directory filter when canceling path edits

chengyongru49f9438bac59
diff --git a/webui/src/components/thread/WorkspaceControls.tsx b/webui/src/components/thread/WorkspaceControls.tsx
index faebc0aee..21976e5da 100644
--- a/webui/src/components/thread/WorkspaceControls.tsx
+++ b/webui/src/components/thread/WorkspaceControls.tsx
@@ -512,7 +512,7 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
const visit = captureVisit();
setHistory(current => {
const visits = [...current.visits];
- visits[current.index] = { ...visit, filter: "" };
+ visits[current.index] = visit;
return { ...current, visits };
});
setEditingPath(true);
@@ -521,7 +521,7 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
}
function cancelPathEditing(focusColumns = true) {
setEditingPath(false);
- changeDraft(workspaceDirectoryPrefix(basePath));
+ changeDraft(workspaceDirectoryPrefix(basePath), filterQuery.trim());
if (focusColumns) focusDirectory();
}
diff --git a/webui/src/tests/workspace-picker.test.tsx b/webui/src/tests/workspace-picker.test.tsx
index 621aaf15d..58e598868 100644
--- a/webui/src/tests/workspace-picker.test.tsx
+++ b/webui/src/tests/workspace-picker.test.tsx
@@ -607,10 +607,15 @@ describe("Workspace project picker", () => {
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ project_path: "/srv/new/" }));
});
- it("filters the current folder separately from address editing", async () => {
+ it.each(["Escape", "outside"])("preserves directory filtering when path editing is canceled with %s", async (cancel) => {
const user = userEvent.setup();
- const onBrowse = vi.fn().mockResolvedValue(directory);
- render(<WorkspaceProjectPicker isHero scope={scope} defaultScope={scope} controls={catalog.controls} onBrowseDirectories={onBrowse} onChange={vi.fn()} />);
+ const onChange = vi.fn();
+ const onBrowse = vi.fn((raw: string, query: string) => {
+ const path = raw.replace(/\/$/, "");
+ const names = path === scope.project_path ? ["alpha", "beta"] : ["child"];
+ return Promise.resolve({ ...directory, path, entries: names.filter(name => name.includes(query)).map(name => ({ name, path: `${path}/${name}` })) });
+ });
+ render(<WorkspaceProjectPicker isHero scope={scope} defaultScope={scope} controls={catalog.controls} onBrowseDirectories={onBrowse} onChange={onChange} />);
await user.click(screen.getByRole("button", { name: "Switch working directory" }));
await screen.findByRole("option", { name: "/srv/workspace/alpha" });
const input = screen.getByRole("textbox", { name: "Filter this folder" });
@@ -620,6 +625,16 @@ describe("Workspace project picker", () => {
await user.click(screen.getByRole("button", { name: /^Edit path:/ }));
expect(input).toBeDisabled();
expect(screen.getByRole("combobox")).toHaveValue("/srv/workspace/");
+ fireEvent.change(screen.getByRole("combobox"), { target: { value: "/srv/other/" } });
+ await screen.findByRole("option", { name: "/srv/other/child" });
+ if (cancel === "Escape") await user.keyboard("{Escape}");
+ else await user.click(screen.getByRole("listbox", { name: "/srv/other" }));
+ expect(input).toBeEnabled();
+ expect(input).toHaveValue("alp");
+ await screen.findByRole("option", { name: "/srv/workspace/alpha" });
+ expect(screen.queryByRole("option", { name: "/srv/workspace/beta" })).not.toBeInTheDocument();
+ expect(screen.queryByRole("option", { name: "/srv/other/child" })).not.toBeInTheDocument();
+ expect(onChange).not.toHaveBeenCalled();
});
it("moves to the focused column's parent with the left arrow", async () => {
const user = userEvent.setup();