fix(editor): align the line and column dialog (#4693)

Go to Line puts its label and coordinate field on one row in the workbench UI font, and opening it selects the current coordinates so they can be typed over.
This commit is contained in:
l0ng-ai
2026-11-20 14:17:45 +08:00
committed by GitHub
parent 94e318e740
commit d47e9688cb
9 changed files with 57 additions and 18 deletions
+33
View File
@@ -55,6 +55,39 @@ test("⌘F opens the find bar and highlights matches; Escape returns to the edit
await expect(editor.locator(".cm-content")).toBeFocused();
});
test("Go to Line keeps its label beside the selected coordinates and returns focus to the editor", async ({
workbench: page,
}) => {
const editor = await openFromTree(page, "build.gradle.kts");
const content = editor.locator(".cm-content");
await content.focus();
await page.keyboard.press("Meta+l");
const dialog = page.getByRole("dialog", { name: "Go to Line:Column", exact: true });
const coordinates = dialog.getByRole("textbox", { name: "Line and column", exact: true });
await expect(coordinates).toBeFocused();
await expect(coordinates).toHaveValue("1:1");
expect(await coordinates.evaluate((el: HTMLInputElement) => [el.selectionStart, el.selectionEnd])).toEqual([0, 3]);
await page.setViewportSize({ width: 360, height: 500 });
const label = dialog.getByText("Line and column", { exact: true });
await expect(label).toBeVisible();
const text = (await label.boundingBox())!;
const field = (await coordinates.boundingBox())!;
expect(text.x + text.width).toBeLessThan(field.x);
expect(Math.abs(text.y + text.height / 2 - field.y - field.height / 2)).toBeLessThan(2);
await expect(coordinates).toHaveCSS("font-size", await label.evaluate((el) => getComputedStyle(el).fontSize));
await coordinates.fill("0:2");
await expect(coordinates).toHaveAttribute("aria-invalid", "true");
await expect(dialog.getByRole("button", { name: "OK", exact: true })).toBeDisabled();
await coordinates.fill("6:8");
await coordinates.press("Enter");
await expect(dialog).toBeHidden();
await expect(content).toBeFocused();
await page.setViewportSize({ width: 960, height: 600 });
await expect(page.getByRole("button", { name: "6:8", exact: true })).toBeVisible();
});
test("each file keeps its own find bar, query and caret", async ({ workbench: page }) => {
const find = page.getByRole("textbox", { name: "Find" });
const caret = page.getByRole("button", { name: /^\d+:\d+/ });
+11 -4
View File
@@ -275,12 +275,19 @@
/* Go to line */
.gotoBody {
display: flex;
flex-direction: column;
gap: var(--space-2);
padding: 8px 16px 0;
display: grid;
grid-template-columns: fit-content(50%) minmax(0, 1fr);
align-items: center;
gap: var(--space-1) var(--space-2);
padding: var(--space-1) var(--space-4) 0;
}
.gotoLabel {
overflow-wrap: anywhere;
color: var(--fg);
font-size: var(--fs-ui);
}
.gotoHint {
grid-column: 2;
color: var(--fg-subtle);
font-size: var(--fs-small);
}
+13 -8
View File
@@ -1,9 +1,8 @@
/** ⌘L: "Go to Line:Column" (1-based `line[:col]`). */
import { useState, type FormEvent } from "react";
import { Dialog, Input } from "@/ui";
import { useId, useState, type FormEvent } from "react";
import { Dialog, Input, T } from "@/ui";
import { editorController, useEditorStatus, useGotoLine } from "../controller";
import styles from "./EditorArea.module.css";
import { tx } from "@/platform/i18n";
export function parseLineCol(text: string): { line: number; col: number } | null {
const m = /^\s*(\d+)\s*(?:[:,]\s*(\d+))?\s*$/.exec(text);
@@ -22,6 +21,7 @@ export function GotoLineDialog() {
function GotoLineInner() {
const status = useEditorStatus((s) => s.status);
const coordinatesId = useId();
const [value, setValue] = useState(() => (status ? `${status.line + 1}:${status.col + 1}` : ""));
const parsed = parseLineCol(value);
const close = () => useGotoLine.setState({ open: false });
@@ -43,19 +43,24 @@ function GotoLineInner() {
]}
>
<form onSubmit={submit} className={styles.gotoBody}>
<label className={styles.gotoLabel} htmlFor={coordinatesId}>
<T>Line and column</T>
</label>
<Input
id={coordinatesId}
data-autofocus=""
mono
value={value}
invalid={!!value && !parsed}
onChange={(e) => setValue(e.target.value)}
onFocus={(e) => e.currentTarget.select()}
aria-label="Line and column"
aria-describedby={status ? undefined : `${coordinatesId}-hint`}
placeholder="line[:column]"
/>
<span className={styles.gotoHint}>
{status ? tx`Current position ${status.line + 1}:${status.col + 1}` : tx("No active editor")}
</span>
{!status && (
<span className={styles.gotoHint} id={`${coordinatesId}-hint`}>
<T>No active editor</T>
</span>
)}
</form>
</Dialog>
);
-1
View File
@@ -4625,7 +4625,6 @@
"HEAD is detached; check out a branch to push.": "HEAD está desacoplado; cambie a una rama para hacer push.",
"No shelved changes": "No hay cambios en el estante",
"No recent projects": "No hay proyectos recientes",
"Current position {line}:{col}": "Posición actual {line}:{col}",
"{count} detected folders are unmarked.": "{count} carpetas detectadas están desmarcadas.",
"Rebase commits of {head} not on:": "Hacer rebase de las confirmaciones de {head} que no están en:",
"{head} has no upstream: commits up to {revision} will be pushed as a new branch:": "{head} no tiene rama remota de seguimiento (upstream): las confirmaciones hasta {revision} se enviarán con push como una rama nueva:",
-1
View File
@@ -4480,7 +4480,6 @@
"HEAD is detached; check out a branch to push.": "HEAD est détachée ; extrayez une branche pour pousser.",
"No shelved changes": "Aucune modification mise de côté",
"No recent projects": "Aucun projet récent",
"Current position {line}:{col}": "Position actuelle {line}:{col}",
"{count} detected folders are unmarked.": "{count} dossiers détectés ne sont pas marqués.",
"Rebase commits of {head} not on:": "Rebaser les commits de {head} absents de :",
"{head} has no upstream: commits up to {revision} will be pushed as a new branch:": "{head} n'a pas de branche amont : les commits jusqu'à {revision} seront poussés comme nouvelle branche :",
-1
View File
@@ -4693,7 +4693,6 @@
"HEAD is detached; check out a branch to push.": "HEAD가 분리되었습니다. 푸시하려면 브랜치를 체크아웃하세요.",
"No shelved changes": "보류된 변경 사항 없음",
"No recent projects": "최근 프로젝트 없음",
"Current position {line}:{col}": "현재 위치 {line}:{col}",
"{count} detected folders are unmarked.": "감지된 폴더 {count}개가 표시되지 않았습니다.",
"Rebase commits of {head} not on:": "다음에 없는 {head}의 커밋 리베이스:",
"{head} has no upstream: commits up to {revision} will be pushed as a new branch:": "{head}에 업스트림이 없습니다. {revision}까지의 커밋이 새 브랜치로 푸시됩니다:",
-1
View File
@@ -4577,7 +4577,6 @@
"HEAD is detached; check out a branch to push.": "Wskaźnik HEAD jest odłączony; przełącz się na gałąź, aby wykonać push.",
"No shelved changes": "Brak odłożonych zmian (shelved)",
"No recent projects": "Brak ostatnich projektów",
"Current position {line}:{col}": "Bieżąca pozycja: {line}:{col}",
"{count} detected folders are unmarked.": "Wykryte foldery w liczbie {count} nie zostały zaznaczone.",
"Rebase commits of {head} not on:": "Wykonaj rebase zatwierdzeń {head} nieobecnych w:",
"{head} has no upstream: commits up to {revision} will be pushed as a new branch:": "Gałąź {head} nie ma ustawionego repozytorium nadrzędnego (upstream): zatwierdzenia do wersji {revision} zostaną wysłane jako nowa gałąź:",
-1
View File
@@ -4591,7 +4591,6 @@
"HEAD is detached; check out a branch to push.": "HEAD está desanexada; faça checkout de uma branch para fazer push.",
"No shelved changes": "Nenhuma alteração no shelf",
"No recent projects": "Nenhum projeto recente",
"Current position {line}:{col}": "Posição atual {line}:{col}",
"{count} detected folders are unmarked.": "{count} pastas detectadas não estão marcadas.",
"Rebase commits of {head} not on:": "Fazer rebase dos commits de {head} ausentes em:",
"{head} has no upstream: commits up to {revision} will be pushed as a new branch:": "{head} não tem upstream: commits até {revision} serão enviados com push como uma nova branch:",
-1
View File
@@ -5537,7 +5537,6 @@
"HEAD is detached; check out a branch to push.": "HEAD 处于分离状态;请签出一个分支后再推送。",
"No shelved changes": "没有已搁置的更改",
"No recent projects": "没有最近的项目",
"Current position {line}:{col}": "当前位置 {line}:{col}",
"{count} detected folders are unmarked.": "有 {count} 个检测到的文件夹未标记。",
"Rebase commits of {head} not on:": "变基 {head} 中不在以下分支上的提交:",
"{head} has no upstream: commits up to {revision} will be pushed as a new branch:": "{head} 没有上游分支:截至 {revision} 的提交将作为新分支推送:",