Compare commits

...
Author SHA1 Message Date
l0ng-ai 36d75c8cf1 Merge remote-tracking branch 'origin/main' into fix/project-tree-move-dialog-layout
# Conflicts:
#	src/platform/locales/text/en.json
#	src/platform/locales/text/zh.json
2026-11-20 06:40:05 +08:00
l0ng-ai e4b6a5c9ca fix(project-tree): make the Move dialog readable in narrow windows 2026-11-20 04:49:58 +08:00
5 changed files with 241 additions and 35 deletions

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
const root = "/dev/acme-api";
const name = `InternationalSettlement${"Reconciliation".repeat(10)}.txt`;
const destination = `archive/Approved${"Settlement".repeat(11)}`;
test("keeps a long source name and destination readable while moving a file", async ({ workbench: page }) => {
await page.evaluate(
async ({ root, name, destination }) => {
const fsModule = "/src/features/project-tree/fs.ts";
const { projectFs } = await import(/* @vite-ignore */ fsModule);
const storeModule = "/src/features/project-tree/store.ts";
const { loadDir } = await import(/* @vite-ignore */ storeModule);
const fs = projectFs(root);
await fs.createFile(`${root}/${name}`);
await fs.createDir(`${root}/archive`);
await fs.createDir(`${root}/${destination}`);
await loadDir(root, true);
},
{ root, name, destination },
);
await page.getByRole("treeitem", { name, exact: true }).click();
await page.keyboard.press("F6");
const dialog = page.getByRole("dialog", { name: "Move", exact: true });
const field = dialog.getByRole("textbox", { name: "Target directory" });
await expect(field).toBeFocused();
await page.setViewportSize({ width: 470, height: 480 });
await expect
.poll(() => dialog.locator("[data-dialog-body]").evaluate((el) => el.scrollWidth - el.clientWidth))
.toBeLessThanOrEqual(1);
expect(
await field.evaluate((el: HTMLInputElement) => el.value.slice(el.selectionStart ?? 0, el.selectionEnd ?? 0)),
).toBe("acme-api");
const submit = dialog.getByRole("button", { name: "Refactor", exact: true });
await expect(submit).toBeDisabled();
await field.fill(destination);
await expect(dialog.getByText(destination, { exact: true })).toBeVisible();
await expect(submit).toBeInViewport({ ratio: 1 });
await dialog.getByRole("checkbox", { name: "Search for references" }).uncheck();
await dialog.getByRole("checkbox", { name: "Search in comments and strings" }).uncheck();
await submit.click();
await expect(dialog).toBeHidden();
await expect
.poll(() =>
page.evaluate(
async ({ root, destination }) => {
const fsModule = "/src/features/project-tree/fs.ts";
const { projectFs } = await import(/* @vite-ignore */ fsModule);
return (await projectFs(root).readDir(`${root}/${destination}`)).map((entry: { name: string }) => entry.name);
},
{ root, destination },
),
)
.toEqual([name]);
});
test("browses for a destination and keeps the current path on cancel", async ({ workbench: page }) => {
await page.getByRole("treeitem", { name: "README.md", exact: true }).click();
await stubDesktop(page);
await page.evaluate(() => {
window.__ipc.handlers.file_dialog_needs_gtk = () => false;
let chosen: string | null = null;
window.__ipc.handlers["plugin:dialog|open"] = () => {
const result = chosen;
chosen = "C:\\Projects\\Invoice Archive";
return result;
};
});
await page.keyboard.press("F6");
const dialog = page.getByRole("dialog", { name: "Move", exact: true });
const field = dialog.getByRole("textbox", { name: "Target directory" });
const browse = dialog.getByRole("button", { name: "Browse for target directory", exact: true });
await browse.click();
await expect.poll(() => ipcCalls(page, "plugin:dialog|open")).toHaveLength(1);
await expect(field).toHaveValue(root);
await browse.click();
await expect(field).toHaveValue("C:/Projects/Invoice Archive");
await expect(dialog.getByRole("button", { name: "Refactor", exact: true })).toBeEnabled();
await field.fill("C:/");
await expect(dialog.getByText("C:/", { exact: true })).toBeVisible();
await field.fill("/");
await expect(dialog.getByText("/", { exact: true })).toBeVisible();
await page.keyboard.press("Escape");
await expect(dialog).toBeHidden();
});
@@ -10,6 +10,60 @@
font-size: var(--fs-ui);
}
.moveForm {
display: flex;
flex-direction: column;
gap: var(--space-3);
padding: var(--space-3) var(--space-4);
}
.moveSubject {
color: var(--fg-emphasis);
font-size: var(--fs-ui);
font-weight: 600;
overflow-wrap: anywhere;
}
.moveDestination {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
gap: var(--space-1) var(--space-2);
}
.moveDestination > .fieldLabel {
line-height: var(--h-field);
}
.moveControls {
display: flex;
flex: 1 1 244px;
flex-direction: column;
gap: var(--space-2);
min-width: 0;
}
.moveField {
display: flex;
align-items: center;
gap: var(--space-1);
}
.moveField input {
flex: 1 1 0;
}
.moveField button {
flex: none;
}
.movePath {
color: var(--fg-subtle);
font-size: var(--fs-small);
font-family: var(--font-mono);
overflow-wrap: anywhere;
}
.fieldLabel {
color: var(--fg);
font-size: var(--fs-ui);
@@ -6,7 +6,10 @@
import { useEffect, useRef, useState } from "react";
import { create } from "zustand";
import type { FileMove } from "@/bindings";
import { Checkbox, Dialog, Input, Spinner, T } from "@/ui";
import { Checkbox, Dialog, IconButton, Input, Spinner, T } from "@/ui";
import { choosePath } from "@/platform/choosePath";
import { isTauri } from "@/platform/ipc";
import { ipcPath } from "@/platform/paths";
import { runFileRefactoring, type FileRefactorOptions } from "./fileRefactor";
import {
isSameOrInside,
@@ -253,31 +256,59 @@ function RenameDialog({ request }: { request: Extract<FileRefactorRequest, { kin
/** Folder `typed` (absolute, or relative to the project root). */
function resolveTarget(typed: string, root: string): string {
const t = typed.trim().replace(/\/+$/, "");
if (!t) return root;
return t.startsWith("/") || /^[A-Za-z]:[\\/]/.test(t) ? t : joinPath(root, t);
const value = ipcPath(typed.trim());
if (!value) return root;
const absolute = value.startsWith("/") || /^[A-Za-z]:\//.test(value);
const isRoot = /^(?:[A-Za-z]:)?\/+$/.test(value);
const path = value.replace(/\/+$/, isRoot ? "/" : "");
return absolute ? path : joinPath(root, path);
}
function MoveDialog({ request }: { request: Extract<FileRefactorRequest, { kind: "move" }> }) {
const root = useProjectTree((s) => s.root) ?? "";
const [target, setTarget] = useState(request.target);
const [options, setOptions] = useState(() => loadOptions("move"));
const [browsing, setBrowsing] = useState(false);
const [browseError, setBrowseError] = useState<string | null>(null);
const field = useRef<HTMLInputElement>(null);
const { busy, run, cancel } = useSearch();
useEffect(() => {
const input = field.current;
const path = request.target.replace(/[\\/]+$/, "");
if (!input || !path || /^[A-Za-z]:$/.test(path)) return;
const start = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\")) + 1;
input.setSelectionRange(start, path.length);
input.scrollLeft = input.scrollWidth;
}, [request.target]);
const dest = resolveTarget(target, root);
const moves: FileMove[] = request.paths
.filter((p) => parentOf(p) !== dest)
.map((p) => ({ from: p, to: joinPath(dest, nameOf(p)) }));
.map((from) => ({ from, to: joinPath(dest, nameOf(from)) }))
.filter((move) => move.from !== move.to);
const error = request.paths.some((p) => isSameOrInside(dest, p))
? "Cannot move a folder into itself"
? tx("Cannot move a folder into itself")
: !moves.length
? "Already in this directory"
? tx("Already in this directory")
: null;
const subject =
request.paths.length === 1
? `Move ${request.dir || useProjectTree.getState().listings.has(request.paths[0]!) ? "directory" : "file"} '${nameOf(request.paths[0]!)}'`
: `Move ${request.paths.length} items`;
const single = request.paths.length === 1 ? request.paths[0]! : null;
const subject = single
? request.dir || useProjectTree.getState().listings.has(single)
? tx`Move directory '${nameOf(single)}'`
: tx`Move file '${nameOf(single)}'`
: tx`Move ${request.paths.length} items`;
const browse = async () => {
setBrowsing(true);
setBrowseError(null);
try {
const picked = await choosePath({ directory: true, title: tx("Select Target Directory"), defaultPath: dest });
if (picked !== null) setTarget(ipcPath(picked));
} catch (e) {
setBrowseError(e instanceof Error ? e.message : String(e));
} finally {
setBrowsing(false);
}
};
const submit = async () => {
if (busy || error) return;
if (busy || browsing || error) return;
saveOptions("move", options);
const status = await run(moves, options, "Move");
if (status !== "done") return;
@@ -291,38 +322,59 @@ function MoveDialog({ request }: { request: Extract<FileRefactorRequest, { kind:
width={520}
footerStart={busy ? <Busy /> : undefined}
buttons={[
{ label: "Refactor", role: "default", disabled: busy || !!error, onClick: () => void submit() },
{ label: "Refactor", role: "default", disabled: busy || browsing || !!error, onClick: () => void submit() },
{ label: "Cancel", role: "cancel", onClick: cancel },
]}
>
<form
className={styles.form}
className={styles.moveForm}
onSubmit={(e) => {
e.preventDefault();
void submit();
}}
>
<div className={styles.subject}>{subject}</div>
<label className={styles.fieldLabel} htmlFor="file-move-target">
<T>To directory:</T>
</label>
<Input
id="file-move-target"
autoFocus
mono
value={target}
disabled={busy}
invalid={!!error}
aria-label="Target directory"
onChange={(e) => setTarget(e.target.value)}
/>
<div className={styles.hint}>{relativeTo(root, dest) || (dest === root ? tx("Project root") : dest)}</div>
{error && (
<div className={styles.error} role="alert">
{error}
<div className={styles.moveSubject}>{subject}</div>
<div className={styles.moveDestination}>
<label className={styles.fieldLabel} htmlFor="file-move-target">
<T>To directory:</T>
</label>
<div className={styles.moveControls}>
<div className={styles.moveField}>
<Input
id="file-move-target"
ref={field}
data-autofocus
mono
value={target}
disabled={busy}
invalid={!!error}
aria-label="Target directory"
aria-describedby="file-move-preview"
onChange={(e) => {
setBrowseError(null);
setTarget(e.target.value);
}}
/>
{isTauri() && (
<IconButton
icon="folder-open"
title={tx("Browse for target directory")}
disabled={busy || browsing}
onClick={() => void browse()}
/>
)}
</div>
<div className={styles.movePath} id="file-move-preview" title={dest}>
{relativeTo(root, dest) || (dest === root ? tx("Project root") : dest)}
</div>
{(browseError ?? error) && (
<div className={styles.error} role="alert">
{browseError ?? error}
</div>
)}
<Options value={options} onChange={setOptions} move disabled={busy} />
</div>
)}
<Options value={options} onChange={setOptions} move disabled={busy} />
</div>
</form>
</Dialog>
);
+7
View File
@@ -2739,6 +2739,13 @@
"{description}; JVM options: {flags}": "{description}; JVM options: {flags}",
"Sorting Options": "Sorting Options",
"Sort by Duration": "Sort by Duration",
"Move file '{name}'": "Move file '{name}'",
"Move directory '{name}'": "Move directory '{name}'",
"Move {count} items": "Move {count} items",
"Browse for target directory": "Browse for target directory",
"Select Target Directory": "Select Target Directory",
"Cannot move a folder into itself": "Cannot move a folder into itself",
"Already in this directory": "Already in this directory",
"Resize left merge pane": "Resize left merge pane",
"Resize right merge pane": "Resize right merge pane",
"Database and schema": "Database and schema",
+7
View File
@@ -9109,6 +9109,13 @@
"{description}; JVM options: {flags}": "{description};JVM 选项:{flags}",
"Sorting Options": "排序选项",
"Sort by Duration": "按持续时间排序",
"Move file '{name}'": "移动文件「{name}」",
"Move directory '{name}'": "移动目录「{name}」",
"Move {count} items": "移动 {count} 个项目",
"Browse for target directory": "浏览目标目录",
"Select Target Directory": "选择目标目录",
"Cannot move a folder into itself": "不能将文件夹移动到自身目录中",
"Already in this directory": "已在此目录中",
"Resize left merge pane": "调整左侧合并窗格宽度",
"Resize right merge pane": "调整右侧合并窗格宽度",
"Database and schema": "数据库和 schema",