дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Порівняти коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
87c6563a4f | ||
|
|
9ed87d77a7 | ||
|
|
dfa59aa2f6 |
No files matched your search
@@ -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();
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
import { expect, openFromTree, test } from "./fixtures";
|
||||
|
||||
test("Reformat File aligns scope and option controls and supports arrow-key scope changes", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
const editor = await openFromTree(page, "build.gradle.kts");
|
||||
await editor.locator(".cm-line").first().click();
|
||||
await page.keyboard.press("Home");
|
||||
await page.keyboard.press("Shift+End");
|
||||
await page.evaluate(async () => {
|
||||
const path = "/src/platform/actions.ts";
|
||||
const { executeAction } = await import(/* @vite-ignore */ path);
|
||||
await executeAction("code.reformatDialog");
|
||||
});
|
||||
|
||||
const dialog = page.getByRole("dialog", { name: /Reformat File/ });
|
||||
const scope = dialog.getByRole("group", { name: "Scope" });
|
||||
const selected = scope.getByRole("radio", { name: "Selected text" });
|
||||
await expect(selected).toBeChecked();
|
||||
await expect(scope.getByRole("radio").first()).toHaveAccessibleName("Selected text");
|
||||
await selected.press("ArrowDown");
|
||||
await expect(scope.getByRole("radio", { name: "Whole file" })).toBeChecked();
|
||||
|
||||
const optimize = dialog.getByRole("group", { name: "Options" }).getByRole("checkbox", { name: "Optimize imports" });
|
||||
expect((await selected.boundingBox())!.x).toBeCloseTo((await optimize.boundingBox())!.x, 0);
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(dialog).toBeHidden();
|
||||
});
|
||||
|
||||
test("Reformat Code keeps long targets and the file mask usable in a narrow window", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 340, height: 460 });
|
||||
const target = "InternationalSettlementReconciliation".repeat(4);
|
||||
await page.evaluate(async (target) => {
|
||||
const path = "/src/platform/actions.ts";
|
||||
const { executeAction } = await import(/* @vite-ignore */ path);
|
||||
await executeAction("code.reformatFiles", { directories: [`/dev/acme-api/${target}`] });
|
||||
}, target);
|
||||
|
||||
const dialog = page.getByRole("dialog", { name: "Reformat Code", exact: true });
|
||||
await expect(dialog.getByText(target, { exact: true })).toBeVisible();
|
||||
const body = dialog.locator("[data-dialog-body]");
|
||||
expect(await body.evaluate((el) => el.scrollWidth)).toBe(await body.evaluate((el) => el.clientWidth));
|
||||
|
||||
await expect(
|
||||
dialog.getByRole("group", { name: "Options" }).getByRole("checkbox", { name: "Include subdirectories" }),
|
||||
).toBeChecked();
|
||||
const filters = dialog.getByRole("group", { name: "Filters" });
|
||||
const mask = filters.getByRole("textbox", { name: "File mask" });
|
||||
await expect(mask).toBeDisabled();
|
||||
await filters.getByText("File mask:", { exact: true }).click();
|
||||
await mask.fill("*.java");
|
||||
await expect(mask).toHaveValue("*.java");
|
||||
await dialog.getByRole("button", { name: "Cancel" }).click();
|
||||
await expect(dialog).toBeHidden();
|
||||
});
|
||||
@@ -553,33 +553,6 @@
|
||||
}
|
||||
|
||||
/* Dialog bodies get no padding of their own; wrap the groups like Analysis dialogs' .form. */
|
||||
.reformatBody {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 14px;
|
||||
}
|
||||
.reformatGroup {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-1-5);
|
||||
}
|
||||
.reformatLegend {
|
||||
margin-bottom: 6px;
|
||||
padding: 0;
|
||||
font-size: var(--fs-small);
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.reformatOption {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1-5);
|
||||
font-size: var(--fs-ui);
|
||||
}
|
||||
|
||||
.pasteImports {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { act, fireEvent, render, screen } from "@testing-library/react";
|
||||
import { act, fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import type { Location } from "@/bindings";
|
||||
|
||||
const openFile = vi.fn(async () => undefined);
|
||||
@@ -19,7 +19,6 @@ const { closePopup, openPopup, useLspPopup } = await import("./popupStore");
|
||||
const { useDocWindow, hoverDoc, pushHistory, stepHistory, hoverCandidates } = await import("./docs");
|
||||
const { mountHoverDoc } = await import("./DocView");
|
||||
const { hoverSource } = await import("./hover");
|
||||
import popupStyles from "./Popups.module.css";
|
||||
import { registerImportsOnPasteActions } from "./importsOnPaste";
|
||||
import { EditorState } from "@codemirror/state";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
@@ -352,7 +351,7 @@ describe("quick definition popup", () => {
|
||||
});
|
||||
|
||||
describe("reformat dialog", () => {
|
||||
it("wraps its content in the padded body", () => {
|
||||
it("offers only whole-file formatting when the editor has no selection", () => {
|
||||
const onRun = vi.fn();
|
||||
openPopup({
|
||||
kind: "reformat",
|
||||
@@ -363,9 +362,10 @@ describe("reformat dialog", () => {
|
||||
onRun,
|
||||
});
|
||||
render(<LspPopups />);
|
||||
const body = screen.getByRole("dialog", { name: "Reformat File" }).querySelector("[data-dialog-body]")!;
|
||||
expect(body.firstElementChild).toHaveClass(popupStyles.reformatBody!);
|
||||
expect(body.firstElementChild!.querySelectorAll("fieldset")).toHaveLength(2);
|
||||
const scope = within(screen.getByRole("group", { name: "Scope" }));
|
||||
expect(scope.getByRole("radio", { name: "Selected text" })).toBeDisabled();
|
||||
expect(scope.getByRole("radio", { name: "Whole file" })).toBeChecked();
|
||||
expect(within(screen.getByRole("group", { name: "Options" })).getByRole("checkbox")).not.toBeChecked();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Run" }));
|
||||
expect(onRun).toHaveBeenCalledWith({ selectionOnly: false, optimizeImports: false });
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
List,
|
||||
MenuList,
|
||||
Popup,
|
||||
Radio,
|
||||
Select,
|
||||
Spinner,
|
||||
SymbolBadge,
|
||||
@@ -35,6 +36,7 @@ import { renderCode } from "./markdown";
|
||||
import { describeSummary } from "./workspaceEdit";
|
||||
import { useUsagesStatus } from "./navigation";
|
||||
import styles from "./Popups.module.css";
|
||||
import fieldsetStyles from "@/ui/DialogFieldset.module.css";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
|
||||
@@ -681,7 +683,7 @@ function ReformatDialog({ popup }: { popup: Extract<LspPopup, { kind: "reformat"
|
||||
open
|
||||
onClose={closePopup}
|
||||
title={popup.title}
|
||||
width={380}
|
||||
width={400}
|
||||
buttons={[
|
||||
{
|
||||
label: "Run",
|
||||
@@ -695,33 +697,27 @@ function ReformatDialog({ popup }: { popup: Extract<LspPopup, { kind: "reformat"
|
||||
{ label: "Cancel", role: "cancel" },
|
||||
]}
|
||||
>
|
||||
<div className={styles.reformatBody}>
|
||||
<fieldset className={styles.reformatGroup}>
|
||||
<legend className={styles.reformatLegend}>
|
||||
<div className={fieldsetStyles.body}>
|
||||
<fieldset className={fieldsetStyles.group}>
|
||||
<legend className={fieldsetStyles.legend}>
|
||||
<T>Scope</T>
|
||||
</legend>
|
||||
<label className={styles.reformatOption}>
|
||||
<input
|
||||
type="radio"
|
||||
name="reformat-scope"
|
||||
checked={!selectionOnly}
|
||||
onChange={() => setSelectionOnly(false)}
|
||||
/>
|
||||
<T>Whole file</T>
|
||||
</label>
|
||||
<label className={clsx(styles.reformatOption, !popup.hasSelection && styles.disabled)}>
|
||||
<input
|
||||
type="radio"
|
||||
name="reformat-scope"
|
||||
checked={selectionOnly}
|
||||
disabled={!popup.hasSelection}
|
||||
onChange={() => setSelectionOnly(true)}
|
||||
/>
|
||||
<T>Selected text</T>
|
||||
</label>
|
||||
<Radio
|
||||
name="reformat-scope"
|
||||
checked={selectionOnly}
|
||||
disabled={!popup.hasSelection}
|
||||
onChange={() => setSelectionOnly(true)}
|
||||
label="Selected text"
|
||||
/>
|
||||
<Radio
|
||||
name="reformat-scope"
|
||||
checked={!selectionOnly}
|
||||
onChange={() => setSelectionOnly(false)}
|
||||
label="Whole file"
|
||||
/>
|
||||
</fieldset>
|
||||
<fieldset className={styles.reformatGroup}>
|
||||
<legend className={styles.reformatLegend}>
|
||||
<fieldset className={fieldsetStyles.group}>
|
||||
<legend className={fieldsetStyles.legend}>
|
||||
<T>Options</T>
|
||||
</legend>
|
||||
<Checkbox
|
||||
|
||||
@@ -199,6 +199,21 @@
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
.reformatSubject {
|
||||
overflow-wrap: anywhere;
|
||||
font-size: var(--fs-ui);
|
||||
font-weight: 600;
|
||||
}
|
||||
.reformatMask {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
.reformatMaskInput {
|
||||
flex: 1 1 12ch;
|
||||
min-width: 0;
|
||||
}
|
||||
.languageSelect {
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
type StructuralForm,
|
||||
} from "./structural";
|
||||
import styles from "./Analysis.module.css";
|
||||
import fieldsetStyles from "@/ui/DialogFieldset.module.css";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { notifications } from "@/workbench/contributions";
|
||||
|
||||
@@ -168,40 +169,50 @@ function ReformatCodeDialog({ targets, onClose }: { targets: readonly ReformatTa
|
||||
{ label: "Cancel", role: "cancel" },
|
||||
]}
|
||||
>
|
||||
<div className={styles.form}>
|
||||
<div className={styles.hint}>{subject}</div>
|
||||
{targets.some((t) => t.dir) && (
|
||||
<div className={fieldsetStyles.body}>
|
||||
<div className={styles.reformatSubject}>{subject}</div>
|
||||
<fieldset className={fieldsetStyles.group}>
|
||||
<legend className={fieldsetStyles.legend}>
|
||||
<T>Options</T>
|
||||
</legend>
|
||||
<Checkbox
|
||||
checked={options.recursive}
|
||||
onChange={(recursive) => setOptions({ ...options, recursive })}
|
||||
label="Include subdirectories"
|
||||
checked={options.optimizeImports}
|
||||
onChange={(optimizeImports) => setOptions({ ...options, optimizeImports })}
|
||||
label="Optimize imports"
|
||||
/>
|
||||
)}
|
||||
<Checkbox
|
||||
checked={options.optimizeImports}
|
||||
onChange={(optimizeImports) => setOptions({ ...options, optimizeImports })}
|
||||
label="Optimize imports"
|
||||
/>
|
||||
<Checkbox
|
||||
checked={options.changedTextOnly}
|
||||
onChange={(changedTextOnly) => setOptions({ ...options, changedTextOnly })}
|
||||
label="Only VCS changed text"
|
||||
/>
|
||||
<div className={styles.fieldRow}>
|
||||
<Checkbox
|
||||
checked={options.useMask}
|
||||
onChange={(useMask) => setOptions({ ...options, useMask })}
|
||||
label="File mask:"
|
||||
checked={options.changedTextOnly}
|
||||
onChange={(changedTextOnly) => setOptions({ ...options, changedTextOnly })}
|
||||
label="Only VCS changed text"
|
||||
/>
|
||||
<Input
|
||||
className={styles.grow}
|
||||
value={options.mask}
|
||||
disabled={!options.useMask}
|
||||
placeholder="*.sh, *.py"
|
||||
onChange={(e) => setOptions({ ...options, mask: e.target.value })}
|
||||
aria-label="File mask"
|
||||
/>
|
||||
</div>
|
||||
{targets.some((t) => t.dir) && (
|
||||
<Checkbox
|
||||
checked={options.recursive}
|
||||
onChange={(recursive) => setOptions({ ...options, recursive })}
|
||||
label="Include subdirectories"
|
||||
/>
|
||||
)}
|
||||
</fieldset>
|
||||
<fieldset className={fieldsetStyles.group}>
|
||||
<legend className={fieldsetStyles.legend}>
|
||||
<T>Filters</T>
|
||||
</legend>
|
||||
<div className={styles.reformatMask}>
|
||||
<Checkbox
|
||||
checked={options.useMask}
|
||||
onChange={(useMask) => setOptions({ ...options, useMask })}
|
||||
label="File mask:"
|
||||
/>
|
||||
<Input
|
||||
className={styles.reformatMaskInput}
|
||||
value={options.mask}
|
||||
disabled={!options.useMask}
|
||||
placeholder="*.sh, *.py"
|
||||
onChange={(e) => setOptions({ ...options, mask: e.target.value })}
|
||||
aria-label="File mask"
|
||||
/>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div className={styles.hint}>
|
||||
<T>Files are reformatted by their language's formatter and saved; files without one are skipped.</T>
|
||||
</div>
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
@@ -2486,6 +2486,8 @@
|
||||
"{length} selected items": "{length} selected items",
|
||||
"Include subdirectories": "Include subdirectories",
|
||||
"Only VCS changed text": "Only VCS changed text",
|
||||
"Options": "Options",
|
||||
"Filters": "Filters",
|
||||
"Files are reformatted by their language's formatter and saved; files without one are skipped.": "Files are reformatted by their language's formatter and saved; files without one are skipped.",
|
||||
"No changed files to reformat": "No changed files to reformat",
|
||||
"No files to reformat": "No files to reformat",
|
||||
@@ -2739,6 +2741,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",
|
||||
|
||||
@@ -8875,6 +8875,7 @@
|
||||
"{length} selected items": "已选择 {length} 项",
|
||||
"Include subdirectories": "包含子目录",
|
||||
"Only VCS changed text": "仅 VCS 更改的文本",
|
||||
"Filters": "筛选条件",
|
||||
"Files are reformatted by their language's formatter and saved; files without one are skipped.": "文件由各自语言的格式化程序重新格式化并保存;没有格式化程序的文件将被跳过。",
|
||||
"No changed files to reformat": "没有需要重新格式化的已更改文件",
|
||||
"No files to reformat": "没有需要重新格式化的文件",
|
||||
@@ -9109,6 +9110,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",
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
.body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
padding: var(--space-4);
|
||||
font-size: var(--fs-ui);
|
||||
}
|
||||
|
||||
.group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-2);
|
||||
min-inline-size: 0;
|
||||
margin: 0;
|
||||
padding: var(--space-2) 0 0;
|
||||
border: 0;
|
||||
border-block-start: 1px solid var(--border-popup);
|
||||
}
|
||||
|
||||
.legend {
|
||||
padding: 0 var(--space-2) 0 0;
|
||||
color: var(--fg-strong);
|
||||
font-weight: 600;
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача