diff --git a/e2e/directoryCompareLayout.spec.ts b/e2e/directoryCompareLayout.spec.ts index 148b53427..49e5d9489 100644 --- a/e2e/directoryCompareLayout.spec.ts +++ b/e2e/directoryCompareLayout.spec.ts @@ -59,10 +59,10 @@ test("directory comparison mirrors both sides and keeps the headers aligned whil const grid = page.getByRole("grid", { name: "Compared files" }); const filter = page.getByRole("textbox", { name: "Filter by name" }); - const source = page.getByText("Left: source", { exact: true }); - const target = page.getByText("Right: target", { exact: true }); - await expect(source).toBeVisible(); - await expect(target).toBeVisible(); + const source = page.getByRole("textbox", { name: "Left folder" }); + const target = page.getByRole("textbox", { name: "Right folder" }); + await expect(source).toHaveValue("/dev/acme-api/source"); + await expect(target).toHaveValue("/dev/acme-api/target"); const [pathBox, filterBox] = await Promise.all([source.boundingBox(), filter.boundingBox()]); if (!pathBox || !filterBox) throw new Error("Missing comparison toolbar bounds"); expect(pathBox.y).toBeGreaterThanOrEqual(filterBox.y + filterBox.height); @@ -99,6 +99,7 @@ test("directory comparison mirrors both sides and keeps the headers aligned whil const shared = grid.getByRole("gridcell", { name: "shared.txt", exact: true }); await expect(shared).toHaveCount(2); await shared.first().click(); - await expect(page.getByRole("button", { name: "Copy to Right", exact: true })).toBeEnabled(); + // An identical file's row does nothing by default, so there is nothing to synchronize. + await expect(page.getByRole("button", { name: "Synchronize Selected", exact: true })).toBeDisabled(); await expect(page.getByRole("toolbar", { name: "Diff", exact: true })).toBeVisible(); }); diff --git a/src/features/vcs/DirectoryCompare.module.css b/src/features/vcs/DirectoryCompare.module.css index af70ba746..1fbaf351a 100644 --- a/src/features/vcs/DirectoryCompare.module.css +++ b/src/features/vcs/DirectoryCompare.module.css @@ -21,13 +21,12 @@ .path { display: flex; align-items: center; - gap: var(--space-2); + gap: var(--space-1); + min-width: 0; +} +.pathInput { + flex: 1; min-width: 0; - min-height: var(--h-field); - padding-inline: var(--space-2); - border-radius: var(--radius-control); - background: var(--bg-field); - box-shadow: inset 0 0 0 1px var(--border); } .path:last-child { grid-column: 3; diff --git a/src/features/vcs/DirectoryCompare.tsx b/src/features/vcs/DirectoryCompare.tsx index e9be62256..94740d027 100644 --- a/src/features/vcs/DirectoryCompare.tsx +++ b/src/features/vcs/DirectoryCompare.tsx @@ -29,12 +29,13 @@ import { lazyComponent, type IconName, } from "@/ui"; -import type { EditorInput } from "@/workbench/contributions"; +import { editorService, type EditorInput } from "@/workbench/contributions"; +import { choosePath } from "@/platform/choosePath"; import { upsertTask } from "@/workbench/tasks"; import { confirmDialog } from "./dialogs"; import { diffInput, openVcsDiff, type DiffData, type DiffSide } from "./diffInput"; -import { compareFilesData, displayPath } from "./compareData"; -import type { DirectoryCompareData } from "./directoryCompareKind"; +import { compareFilesData } from "./compareData"; +import { directoryCompareInput, type DirectoryCompareData } from "./directoryCompareKind"; import { formatSize, formatTime } from "./model"; import styles from "./DirectoryCompare.module.css"; import { useRowHeight } from "@/ui/density"; @@ -190,7 +191,18 @@ export function directoryRows( export function DirectoryCompareEditor({ input }: { input: EditorInput }) { const { left, right } = input.data as DirectoryCompareData; - return ; + return ( + { + // ponytail: reopens as a new tab and closes this one; an in-place input update would keep the tab's position. + void editorService() + .openInput(directoryCompareInput(l, r), { focus: true }) + .then(() => editorService().closeInput?.(input.key)); + }} + /> + ); } const COLUMNS = { @@ -274,7 +286,69 @@ function SyncCell({ ); } -export function DirectoryCompare({ left, right }: { left: string; right: string }) { +/** An editable folder path with a chooser; Enter or leaving the field compares the typed folder. */ +function PathField({ + side, + path, + disabled, + onCommit, +}: { + side: "left" | "right"; + path: string; + disabled: boolean; + onCommit: (path: string) => void; +}) { + const [draft, setDraft] = useState(path); + const label = side === "left" ? "Left folder" : "Right folder"; + const commit = (next: string) => { + if (next.trim() && next.trim() !== path) onCommit(next.trim()); + }; + return ( + + setDraft(e.target.value)} + onBlur={() => commit(draft)} + onKeyDown={(e) => { + if (e.key === "Enter") commit(draft); + else if (e.key === "Escape" && draft !== path) { + e.stopPropagation(); + setDraft(path); + } + }} + /> + { + const picked = await choosePath({ directory: true, title: label, defaultPath: path }); + if (picked) { + setDraft(picked); + commit(picked); + } + }} + /> + + ); +} + +export function DirectoryCompare({ + left, + right, + onPathsChange, +}: { + left: string; + right: string; + /** Compares other folders (the tab is replaced); without it the paths are read-only. */ + onPathsChange?: (left: string, right: string) => void; +}) { const rowHeight = useRowHeight(22); const t = useTx(); const [entries, setEntries] = useState([]); @@ -288,6 +362,7 @@ export function DirectoryCompare({ left, right }: { left: string; right: string const [operating, setOperating] = useState(false); const [error, setError] = useState(null); const [operationError, setOperationError] = useState(null); + const [pathError, setPathError] = useState(null); const [progress, setProgress] = useState(null); const [cancelled, setCancelled] = useState(false); const cancel = useRef<() => void>(() => {}); @@ -369,6 +444,18 @@ export function DirectoryCompare({ left, right }: { left: string; right: string if (data) void openVcsDiff(data); }; + const changePath = async (side: "left" | "right", path: string) => { + setPathError(null); + const next = side === "left" ? { left: path, right } : { left, right: path }; + try { + if ((await call(commands.fsEntryKind(path))) !== "dir") throw new Error(tx`${path} is not a folder`); + if (next.left === next.right) throw new Error(tx("Choose two different folders")); + onPathsChange?.(next.left, next.right); + } catch (e) { + if (mounted.current) setPathError(e instanceof Error ? e.message : String(e)); + } + }; + const actionOf = (e: DirectoryCompareEntry) => actions.get(e.path) ?? syncChoices(e)[0]!; const cycle = (e: DirectoryCompareEntry) => { if (busy || operating) return; @@ -576,15 +663,21 @@ export function DirectoryCompare({ left, right }: { left: string; right: string )}
- - - {tx`Left: ${displayPath(left)}`} - - - - {tx`Right: ${displayPath(right)}`} - + {(["left", "right"] as const).map((side) => ( + void changePath(side, path)} + /> + ))}
+ {pathError && ( +
+ {tx(pathError)} +
+ )} {error && (
{tx(error)} diff --git a/src/features/vcs/__tests__/directoryCompare.test.tsx b/src/features/vcs/__tests__/directoryCompare.test.tsx index dbc2d94c8..79a616029 100644 --- a/src/features/vcs/__tests__/directoryCompare.test.tsx +++ b/src/features/vcs/__tests__/directoryCompare.test.tsx @@ -6,6 +6,8 @@ const mocks = vi.hoisted(() => ({ compare: vi.fn(), cancel: vi.fn(), sync: vi.fn(), + kind: vi.fn(), + choose: vi.fn(), confirm: vi.fn(), open: vi.fn(), })); @@ -17,6 +19,7 @@ vi.mock("@/platform/ipc", async (original) => { ...real.commands, fsCompareDirectories: mocks.compare, fsSynchronizeDirectories: mocks.sync, + fsEntryKind: mocks.kind, cancelRequest: mocks.cancel, }, }; @@ -27,6 +30,7 @@ vi.mock("@tauri-apps/api/core", async (original) => ({ onmessage = () => {}; }, })); +vi.mock("@/platform/choosePath", () => ({ choosePath: mocks.choose })); vi.mock("../DiffEditor", () => ({ DiffEditor: ({ input }: { input: unknown }) =>
{JSON.stringify(input)}
, })); @@ -67,6 +71,7 @@ beforeEach(() => { vi.clearAllMocks(); mocks.compare.mockResolvedValue(ok(rows)); mocks.sync.mockResolvedValue(ok([])); + mocks.kind.mockResolvedValue(ok("dir")); mocks.confirm.mockResolvedValue(true); }); afterEach(cleanup); @@ -234,6 +239,33 @@ describe("disk directory comparison", () => { localStorage.removeItem("openidea.directoryCompare.mode"); }); + it("compares other folders typed into the path fields or chosen with the folder chooser", async () => { + const change = vi.fn(); + render(); + const leftField = screen.getByRole("textbox", { name: "Left folder" }); + expect(leftField).toHaveValue("/p/left"); + fireEvent.change(leftField, { target: { value: "/p/other" } }); + fireEvent.keyDown(leftField, { key: "Enter" }); + await waitFor(() => expect(change).toHaveBeenCalledWith("/p/other", "/p/right")); + expect(mocks.kind).toHaveBeenCalledWith("/p/other"); + // A file, or the folder already on the other side, is refused with a message. + mocks.kind.mockResolvedValueOnce(ok("file")); + const rightField = screen.getByRole("textbox", { name: "Right folder" }); + fireEvent.change(rightField, { target: { value: "/p/file.txt" } }); + fireEvent.blur(rightField); + expect(await screen.findByRole("alert")).toHaveTextContent("/p/file.txt is not a folder"); + fireEvent.change(rightField, { target: { value: "/p/left" } }); + fireEvent.keyDown(rightField, { key: "Enter" }); + expect(await screen.findByText("Choose two different folders")).toBeInTheDocument(); + fireEvent.keyDown(rightField, { key: "Escape" }); + expect(rightField).toHaveValue("/p/right"); + mocks.choose.mockResolvedValueOnce("/p/chosen"); + fireEvent.click(screen.getByRole("button", { name: "Choose right folder" })); + await waitFor(() => expect(change).toHaveBeenCalledWith("/p/left", "/p/chosen")); + expect(mocks.choose).toHaveBeenCalledWith(expect.objectContaining({ directory: true, defaultPath: "/p/right" })); + expect(change).toHaveBeenCalledTimes(2); + }); + it("streams progress, cancels on demand and on close, and ignores stale results after refresh", async () => { let resolve!: (value: unknown) => void; mocks.compare.mockImplementationOnce((_l, _r, _mode, _request, channel) => { diff --git a/src/platform/locales/text/es.json b/src/platform/locales/text/es.json index 8990e530b..109fd082f 100644 --- a/src/platform/locales/text/es.json +++ b/src/platform/locales/text/es.json @@ -5513,8 +5513,6 @@ "Compared files": "Archivos comparados", "Comparison cancelled": "Comparación cancelada", "No matching differences": "No hay diferencias coincidentes", - "Left: {left}": "Izquierda: {left}", - "Right: {right}": "Derecha: {right}", "Compared {compared} of {total} entries": "Se compararon {compared} de {total} entradas", "Scanned {scanned} entries": "Se escanearon {scanned} entradas", "Binary content": "Contenido binario", diff --git a/src/platform/locales/text/fr.json b/src/platform/locales/text/fr.json index b7e3faec1..73bf51425 100644 --- a/src/platform/locales/text/fr.json +++ b/src/platform/locales/text/fr.json @@ -5339,8 +5339,6 @@ "Compared files": "Fichiers comparés", "Comparison cancelled": "Comparaison annulée", "No matching differences": "Aucune différence correspondante", - "Left: {left}": "Gauche : {left}", - "Right: {right}": "Droite : {right}", "Compared {compared} of {total} entries": "{compared} entrées comparées sur {total}", "Scanned {scanned} entries": "{scanned} entrées analysées", "Binary content": "Contenu binaire", diff --git a/src/platform/locales/text/ko.json b/src/platform/locales/text/ko.json index 08f97131a..2a505525b 100644 --- a/src/platform/locales/text/ko.json +++ b/src/platform/locales/text/ko.json @@ -5581,8 +5581,6 @@ "Compared files": "비교된 파일", "Comparison cancelled": "비교가 취소되었습니다", "No matching differences": "일치하는 차이점이 없습니다", - "Left: {left}": "왼쪽: {left}", - "Right: {right}": "오른쪽: {right}", "Compared {compared} of {total} entries": "항목 {total}개 중 {compared}개 비교됨", "Scanned {scanned} entries": "항목 {scanned}개 스캔됨", "Binary content": "바이너리 내용", diff --git a/src/platform/locales/text/pl.json b/src/platform/locales/text/pl.json index 935882b18..cef64f7ad 100644 --- a/src/platform/locales/text/pl.json +++ b/src/platform/locales/text/pl.json @@ -5465,8 +5465,6 @@ "Compared files": "Porównywane pliki", "Comparison cancelled": "Porównywanie anulowane", "No matching differences": "Brak pasujących różnic", - "Left: {left}": "Lewa strona: {left}", - "Right: {right}": "Prawa strona: {right}", "Compared {compared} of {total} entries": "Porównano {compared} z {total} wpisów", "Scanned {scanned} entries": "Przeskanowano wpisy ({scanned})", "Binary content": "Zawartość binarna", diff --git a/src/platform/locales/text/pt.json b/src/platform/locales/text/pt.json index 029d3eb2a..ab82c846b 100644 --- a/src/platform/locales/text/pt.json +++ b/src/platform/locales/text/pt.json @@ -5479,8 +5479,6 @@ "Compared files": "Arquivos comparados", "Comparison cancelled": "Comparação cancelada", "No matching differences": "Nenhuma diferença correspondente", - "Left: {left}": "Esquerda: {left}", - "Right: {right}": "Direita: {right}", "Compared {compared} of {total} entries": "{compared} de {total} entradas comparadas", "Scanned {scanned} entries": "{scanned} entradas verificadas", "Binary content": "Conteúdo binário", diff --git a/src/platform/locales/text/tr.json b/src/platform/locales/text/tr.json index 2e4627513..9ccd3dd14 100644 --- a/src/platform/locales/text/tr.json +++ b/src/platform/locales/text/tr.json @@ -8185,8 +8185,6 @@ "Compared files": "Karşılaştırılan dosyalar", "Comparison cancelled": "Karşılaştırma iptal edildi", "No matching differences": "Eşleşen fark yok", - "Left: {left}": "Sol: {left}", - "Right: {right}": "Sağ: {right}", "Compared {compared} of {total} entries": "{total} öğenin {compared} tanesi karşılaştırıldı", "Scanned {scanned} entries": "{scanned} öğe tarandı", "Binary content": "İkili içerik", diff --git a/src/platform/locales/text/zh-TW.json b/src/platform/locales/text/zh-TW.json index 45fa03f08..a11c64386 100644 --- a/src/platform/locales/text/zh-TW.json +++ b/src/platform/locales/text/zh-TW.json @@ -6510,8 +6510,6 @@ "Compared files": "比較的檔案", "Comparison cancelled": "已取消比較", "No matching differences": "沒有符合的差異", - "Left: {left}": "左側:{left}", - "Right: {right}": "右側:{right}", "Compared {compared} of {total} entries": "已比較 {compared} / {total} 個條目", "Scanned {scanned} entries": "已掃描 {scanned} 個條目", "Binary content": "二進位制內容", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index ebbcb9ba4..9c923f3a3 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -6547,8 +6547,6 @@ "Compared files": "比较的文件", "Comparison cancelled": "已取消比较", "No matching differences": "没有匹配的差异", - "Left: {left}": "左侧:{left}", - "Right: {right}": "右侧:{right}", "Compared {compared} of {total} entries": "已比较 {compared} / {total} 个条目", "Scanned {scanned} entries": "已扫描 {scanned} 个条目", "Binary content": "二进制内容", @@ -6748,6 +6746,12 @@ "Synchronize": "同步", "Synchronize {count} entries? {deletes} will be deleted and {overwrites} overwritten.": "同步 {count} 个条目?其中 {deletes} 个将被删除,{overwrites} 个将被覆盖。", "Synchronizing directories": "正在同步目录", + "Left folder": "左侧文件夹", + "Right folder": "右侧文件夹", + "Choose left folder": "选择左侧文件夹", + "Choose right folder": "选择右侧文件夹", + "{path} is not a folder": "{path} 不是文件夹", + "Choose two different folders": "请选择两个不同的文件夹", "Stop content comparison": "停止内容比较", "Filter:": "筛选:", "Local files": "本地文件",