diff --git a/packages/experimental/client-ui-forge/src/client/ReviewControls.tsx b/packages/experimental/client-ui-forge/src/client/ReviewControls.tsx index f9c43f6677..8c28669352 100644 --- a/packages/experimental/client-ui-forge/src/client/ReviewControls.tsx +++ b/packages/experimental/client-ui-forge/src/client/ReviewControls.tsx @@ -84,7 +84,7 @@ export function SegmentedChoice({ segments, value, choose,
{segments.map((segment) => { const button = ( - ) const tip = segment.disabledTip ?? (counted || segment.count === null ? null : `${segment.label} ${String(segment.count)}`) - return tip === null ? button : {button} + // Every segment keeps its Tooltip, disabled without hover text, so showing or hiding the counts keeps the + // button mounted and the focus on it. + return {button} })}
) diff --git a/packages/experimental/client-ui-forge/src/client/highlight-context.ts b/packages/experimental/client-ui-forge/src/client/highlight-context.ts index da4e3d5788..acff41df2d 100644 --- a/packages/experimental/client-ui-forge/src/client/highlight-context.ts +++ b/packages/experimental/client-ui-forge/src/client/highlight-context.ts @@ -37,9 +37,13 @@ function drawn(text: string): string { */ export function oldSideLines(lines: readonly string[], hunks: readonly ForgeDiffHunk[]): string[] { const old: string[] = [] + // Lines are appended one at a time: spreading a long run of unchanged lines into push would exceed the argument limit. + const copy = (from: number, to?: number): void => { + for (const line of lines.slice(from - 1, to)) old.push(line) + } let at = 1 for (const hunk of hunks) { - old.push(...lines.slice(at - 1, hunk.newStart - 1)) + copy(at, hunk.newStart - 1) at = Math.max(at, hunk.newStart) for (const line of hunk.lines) { const sign = line.charAt(0) @@ -47,7 +51,7 @@ export function oldSideLines(lines: readonly string[], hunks: readonly ForgeDiff if (sign === ' ' || sign === '+') at++ } } - old.push(...lines.slice(at - 1)) + copy(at) return old } diff --git a/packages/experimental/client-ui-forge/src/client/review-threads.ts b/packages/experimental/client-ui-forge/src/client/review-threads.ts index 45bc5722ec..e6cea5675d 100644 --- a/packages/experimental/client-ui-forge/src/client/review-threads.ts +++ b/packages/experimental/client-ui-forge/src/client/review-threads.ts @@ -79,18 +79,6 @@ function spotOf(file: ForgeDiffFile, side: 'L' | 'R', line: number): LineSpot { return { kind: 'gap', index: file.hunks.length } } -/** - * Find the collapsed unchanged lines that hold a line: the index of the hunk they precede, or the hunk count after the last hunk. - * @param file - the diff file. - * @param side - side the line numbers. - * @param line - the line. - * @returns the gap index, or undefined when a hunk shows the line. - */ -export function gapOf(file: ForgeDiffFile, side: 'L' | 'R', line: number): number | undefined { - const spot = spotOf(file, side, line) - return spot.kind === 'gap' ? spot.index : undefined -} - /** * Order a file's threads as its section shows them: threads on the whole file, then threads on lines by the row of their * last line, then outdated threads, then threads the chosen commits do not show. Threads on unchanged lines sort diff --git a/packages/experimental/client-ui-forge/tests/highlight-context.client.spec.tsx b/packages/experimental/client-ui-forge/tests/highlight-context.client.spec.tsx index 0936226874..c58fe113a9 100644 --- a/packages/experimental/client-ui-forge/tests/highlight-context.client.spec.tsx +++ b/packages/experimental/client-ui-forge/tests/highlight-context.client.spec.tsx @@ -39,6 +39,12 @@ describe('oldSideLines', () => { expect(oldSideLines(['a', 'b'], [deletion])).toEqual(['a', 'gone', 'b']) expect(oldSideLines(['a', 'b', 'c'], [{ oldStart: 3, oldLines: 0, newStart: 3, newLines: 1, lines: ['+c'] }])).toEqual(['a', 'b']) }) + + it('rebuilds a file whose unchanged lines outnumber the arguments one call takes', () => { + const lines = Array.from({ length: 200_000 }, (_, at) => `l${String(at + 1)}`) + const old = oldSideLines(lines, [{ oldStart: 150_000, oldLines: 1, newStart: 150_000, newLines: 1, lines: ['-was', '+l150000'] }]) + expect([old.length, old[149_998], old[149_999], old[150_000], old.at(-1)]).toEqual([200_000, 'l149999', 'was', 'l150001', 'l200000']) + }) }) describe('sideRun', () => { diff --git a/packages/experimental/client-ui-forge/tests/review-controls.client.spec.tsx b/packages/experimental/client-ui-forge/tests/review-controls.client.spec.tsx index af3f6aea87..a551d46d19 100644 --- a/packages/experimental/client-ui-forge/tests/review-controls.client.spec.tsx +++ b/packages/experimental/client-ui-forge/tests/review-controls.client.spec.tsx @@ -112,6 +112,18 @@ describe('LensControl width', () => { expect(counts()).toEqual(Array(4).fill(css.count)) }) + it('keeps the focused segment mounted while its count shows or hides', () => { + const { view, counts, resize } = fitted({ cell: 300, counted: 280, labels: 200 }) + const focused = view.getByRole('radio', { name: 'Interface1' }) + focused.focus() + resize(290) + expect(counts()).toEqual(Array(4).fill(css.hiddenCount)) + expect(document.activeElement).toBe(focused) + resize(300) + expect(counts()).toEqual(Array(4).fill(css.count)) + expect(document.activeElement).toBe(focused) + }) + it('measures again when fonts load, and stops once unmounted', () => { const { view, need, counts, widths } = fitted({ cell: 300, counted: 280, labels: 200 }) widths.counted = 290 diff --git a/packages/experimental/client-ui-forge/tests/review-threads.client.spec.ts b/packages/experimental/client-ui-forge/tests/review-threads.client.spec.ts index bc6d56b148..b1710872b7 100644 --- a/packages/experimental/client-ui-forge/tests/review-threads.client.spec.ts +++ b/packages/experimental/client-ui-forge/tests/review-threads.client.spec.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest' import type { ForgeReviewThread } from '@deepseek-ai/dsh-experimental-forge/types' import { - anchorRange, formatThreadQuote, gapOf, inFileOrder, hunkExcerpt, passesFilter, placeThread, threadQuoteSummary, THREAD_FILTERS, + anchorRange, formatThreadQuote, inFileOrder, hunkExcerpt, passesFilter, placeThread, threadQuoteSummary, THREAD_FILTERS, } from '../src/client/review-threads.ts' import { diffFile, reviewComment, reviewThread } from './thread-fixtures.client.ts' @@ -42,19 +42,6 @@ it('names a side and its lines', () => { expect(anchorRange('L', { startLine: 3, endLine: 5 })).toBe('L3–5') }) -it('finds the collapsed unchanged lines that hold a line on either side', () => { - const file = diffFile('a.ts', [ - { oldStart: 5, oldLines: 3, newStart: 5, newLines: 3, lines: [' a', '-b', '+b', ' c'] }, - { oldStart: 20, oldLines: 2, newStart: 22, newLines: 2, lines: ['-x', '+x', ' y'] }, - ]) - expect(gapOf(file, 'R', 2)).toBe(0) - expect(gapOf(file, 'R', 6)).toBeUndefined() - expect(gapOf(file, 'R', 10)).toBe(1) - expect(gapOf(file, 'L', 21)).toBeUndefined() - expect(gapOf(file, 'R', 21)).toBe(1) - expect(gapOf(file, 'R', 40)).toBe(2) -}) - it('orders a file\'s threads as its section shows them', () => { const file = diffFile('a.ts', [ { oldStart: 5, oldLines: 3, newStart: 5, newLines: 3, lines: [' a', '-b', '+b', ' c'] },