diff --git a/e2e/editor.spec.ts b/e2e/editor.spec.ts index 27db94514..28abf93b5 100644 --- a/e2e/editor.spec.ts +++ b/e2e/editor.spec.ts @@ -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+/ }); diff --git a/src/editor/core/view/EditorArea.module.css b/src/editor/core/view/EditorArea.module.css index c813c5257..86c654ecf 100644 --- a/src/editor/core/view/EditorArea.module.css +++ b/src/editor/core/view/EditorArea.module.css @@ -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); } diff --git a/src/editor/core/view/GotoLineDialog.tsx b/src/editor/core/view/GotoLineDialog.tsx index 0f8bbb42f..df757f6b3 100644 --- a/src/editor/core/view/GotoLineDialog.tsx +++ b/src/editor/core/view/GotoLineDialog.tsx @@ -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() { ]} >
+ setValue(e.target.value)} onFocus={(e) => e.currentTarget.select()} - aria-label="Line and column" + aria-describedby={status ? undefined : `${coordinatesId}-hint`} placeholder="line[:column]" /> - - {status ? tx`Current position ${status.line + 1}:${status.col + 1}` : tx("No active editor")} - + {!status && ( + + No active editor + + )}
); diff --git a/src/platform/locales/text/es.json b/src/platform/locales/text/es.json index 300ba6cfa..3be34621f 100644 --- a/src/platform/locales/text/es.json +++ b/src/platform/locales/text/es.json @@ -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:", diff --git a/src/platform/locales/text/fr.json b/src/platform/locales/text/fr.json index 03a87d167..ae131a5bf 100644 --- a/src/platform/locales/text/fr.json +++ b/src/platform/locales/text/fr.json @@ -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 :", diff --git a/src/platform/locales/text/ko.json b/src/platform/locales/text/ko.json index 922fec95c..7b8b7d31a 100644 --- a/src/platform/locales/text/ko.json +++ b/src/platform/locales/text/ko.json @@ -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}까지의 커밋이 새 브랜치로 푸시됩니다:", diff --git a/src/platform/locales/text/pl.json b/src/platform/locales/text/pl.json index e2f8cbce1..632c87919 100644 --- a/src/platform/locales/text/pl.json +++ b/src/platform/locales/text/pl.json @@ -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łąź:", diff --git a/src/platform/locales/text/pt.json b/src/platform/locales/text/pt.json index f037ffa18..5088f890a 100644 --- a/src/platform/locales/text/pt.json +++ b/src/platform/locales/text/pt.json @@ -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:", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index bac88e753..843f8ba87 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -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} 的提交将作为新分支推送:",