Compare commits

...
Author SHA1 Message Date
paseo-bot[bot] 41efe8548e fix(app): highlight single-line chat file citations
A single-line target collapsed the editor selection at the first column. Select the cited text while keeping the cursor at that column.
2026-12-02 12:31:45 +00:00
2 changed files with 21 additions and 7 deletions
+18 -6
View File
@@ -46,6 +46,22 @@ function fitsViewportWidth(element: HTMLElement): boolean {
return element.scrollWidth === element.clientWidth;
}
async function expectSourceLineHighlighted(page: Page, text: string): Promise<void> {
const source = page.getByTestId("file-source-editor").filter({ visible: true });
const line = source.getByText(text, { exact: true });
await expect(line).toBeInViewport();
// CodeMirror draws selection behind the text in a separate layer.
const highlight = source.locator(".cm-selectionBackground");
await expect(highlight, "The cited source line shows a visible selection").toBeVisible();
const [lineBounds, highlightBounds] = await Promise.all([
line.boundingBox(),
highlight.boundingBox(),
]);
expect(highlightBounds!.y + highlightBounds!.height).toBeGreaterThan(lineBounds!.y);
expect(highlightBounds!.y).toBeLessThan(lineBounds!.y + lineBounds!.height);
}
async function replaceEditorText(page: Page, content: string): Promise<void> {
await editor(page).fill(content);
}
@@ -416,9 +432,7 @@ test.describe("CodeMirror workspace file editing", () => {
await expectFileTabOpen(page, "target.ts");
await expect(page.getByTestId("file-source-editor")).toBeVisible();
await expect(page.getByLabel("Line 42, column 1")).toBeVisible();
await expect(
page.getByTestId("file-source-editor").locator(".cm-line", { hasText: "line42 = 42" }),
).toBeVisible();
await expectSourceLineHighlighted(page, "export const line42 = 42;");
const sourceEditor = editor(page);
await sourceEditor.click();
@@ -433,9 +447,7 @@ test.describe("CodeMirror workspace file editing", () => {
await fileLink.click();
await expect(page.getByLabel("Line 42, column 1")).toBeVisible();
await expect(
page.getByTestId("file-source-editor").locator(".cm-line", { hasText: "line42 = 42" }),
).toBeVisible();
await expectSourceLineHighlighted(page, "export const line42 = 42;");
} finally {
await session.cleanup();
}
@@ -120,8 +120,10 @@ export function FileEditorView({
const lineEnd = Math.min(location.lineEnd ?? lineStart, view.state.doc.lines);
const from = view.state.doc.line(lineStart).from;
const to = view.state.doc.line(Math.max(lineStart, lineEnd)).to;
// Keep the cursor at the first column for a single-line citation.
const selection = lineEnd > lineStart ? { anchor: from, head: to } : { anchor: to, head: from };
view.dispatch({
selection: { anchor: from, head: lineEnd > lineStart ? to : from },
selection,
effects: EditorView.scrollIntoView(from, { y: "center" }),
});
}, [location.lineEnd, location.lineStart, navigationRevision]);