Skip to content

feat(diff): find literal text in the loaded patch - #1849

Merged
devswha merged 9 commits into
mainfrom
feat/diff-find
Oct 24, 2026
Merged

devswha merged 9 commits into
mainfrom
feat/diff-find

Conversation

@devswha

@devswha devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner

What this does for the user

The Changes (diff) viewer can now find text in the file's loaded patch. Ctrl/Cmd+F while the viewer has the keyboard, or the new Find button first among its actions, opens a find bar between the header and the rows:

  • The query is matched literally and case-sensitively over added, removed and unchanged lines, including context that is folded away or outside the window of mounted rows.
  • It shows a count (2 of 4, No matches) and the active match's kind and line in words (Removed line 4).
  • Enter / Shift+Enter and Previous / Next step through matches and wrap; the active row gets an accent ring and its text is painted through a CSS highlight, so it is not told by tint alone. A match on a folded line turns Fold context off; an unwrapped row is scrolled across until the match is visible.
  • Escape closes Find first (returning focus to what opened it), then the viewer. Reopening Find shows the kept query and active match.
  • Without a loaded patch (binary, too large, conflict, offline, ...) Find is off and says there is no loaded patch to search. A hint says content outside the patch is not searched; nothing is fetched to widen the search.

Why

The diff rows are virtualized, so the browser's own find cannot reach rows that are not mounted. Searching the patch model instead of the DOM makes every line findable. Precedent: an editor's find bar (Zed, VS Code), scoped to the one virtualized diff (see the DESIGN.md entry).

Notes

  • Ported from a local branch onto current main; the new strings live in src/lib/i18n/files.{ja,ko,zh}.ts after the i18n split, and the demo regression uses the ovis:settings key.
  • The find bar reuses the terminal find bar's Previous match, Next match, Close search, No matches and count strings, so those five keys move from i18n/terminal.*.ts to the base dictionary (as src/lib/i18n.test.ts requires for a key two parts share).
  • Opening Find over the copy fallback's text (shown when the clipboard is blocked) now returns to the diff instead of counting matches in rows that are not mounted.
  • The terminal's own find (Mod+Shift+F) is untouched.

How it was verified

  • bun test src/lib/repoDiffFind.test.ts scripts/ci-browser.test.ts scripts/conventions.test.ts
  • bun run check fast
  • scripts/diff-find-demo-regression.ts (new, in the browser lane): the static demo at 1440 and on a phone (390, DPR 3, touch), light and dark, and in Korean on the phone. It covers counting, stepping and wrapping, the ring and paint, the literal match of pattern punctuation, Escape order and focus return, the disabled state for a binary file, no network request while searching, and that the terminal's find never opens.
  • scripts/repo-diff-browser-qa.ts, extended for Find in the fixture viewer.
  • All of the above pass locally (check fast: typecheck, build, 6388 unit tests, 0 failures; both browser scripts exit 0).
  • Reviewed by a code-review agent and by Codex. Fixed: the stale settings key (HIGH) and Find over the copy fallback (MEDIUM). Left as follow-ups (MEDIUM/LOW, no behaviour regression): centering on very tall wrapped rows reveals the row's middle rather than the match; Ctrl+F is taken alongside Cmd+F on macOS inside the viewer; matchKey/line fields used only by tests.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 8fe7da9 and 6031d81.

Files selected for processing: 21
  • DESIGN.md
  • changelog.d/diff-find.md
  • scripts/ci-browser.sh
  • scripts/ci-browser.test.ts
  • scripts/diff-find-demo-regression.ts
  • scripts/repo-diff-browser-qa.ts
  • scripts/repo-diff-fixture.tsx
  • src/components/RepoDiff.tsx
  • src/components/RepoDiffViewer.css
  • src/components/RepoDiffViewer.tsx
  • src/lib/i18n.ja.ts
  • src/lib/i18n.ko.ts
  • src/lib/i18n.zh.ts
  • src/lib/i18n/files.ja.ts
  • src/lib/i18n/files.ko.ts
  • src/lib/i18n/files.zh.ts
  • src/lib/i18n/terminal.ja.ts
  • src/lib/i18n/terminal.ko.ts
  • src/lib/i18n/terminal.zh.ts
  • src/lib/repoDiffFind.test.ts
  • src/lib/repoDiffFind.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge-pass review-work for 9b9f49c: REVIEW FAILED on keyboard ownership. Everything else about Find checks out.

Blocker: Ctrl/Cmd+F takes over while the command palette has the keyboard. The gate reproduced this in a browser against a fresh demo build. RepoDiffViewer.tsx:156-163 handles Ctrl/Cmd+F whenever the viewer is open, and the palette (App.tsx:888) shields only Escape.

Steps:

  1. Open Files → Changes → src/money.ts.
  2. Press Ctrl+Shift+K. The palette's input has focus.
  3. Press Ctrl+F, then type amount.

The palette stays open with an empty query, and the diff's Find bar underneath it receives amount.

Please take the shortcut only when focus is inside the viewer, or when no dialog sits above it. Add an app-level regression with the palette open over the diff.

Checked and passing:

  • Tests: 42 unit tests pass and the typecheck passes. diff-find-demo-regression passes all 6 runs, and repo-diff-browser-qa exits 0 with 12 Find checks across 4 viewports.
  • Mutants: making matches overlap and making the search ignore case are both caught.
  • Large patch: at the 1 MiB patch limit, the worst query takes 27.6 ms per keystroke.
  • Behaviour:
    • Escape closes Find first and returns focus to whatever opened it.
    • Matches in folded or unmounted rows are found and revealed.
    • A file with no loaded patch says why.
  • Conventions: the moved and new strings are in ja, ko and zh. The precedent is Zed's and VS Code's find bar. CSS uses only tokens, and there are no fixed sleeps.

Non-blocking:

  • Some code in the production files is used only by tests: matchKey and oldLine/newLine.
  • There is an as unknown as VirtualizedFileDiff cast.
  • Ctrl+F suppresses the browser's own find even when there is no patch to search.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Fixed the keyboard-ownership blocker in b9f95d0.

  • RepoDiffViewer.tsx: Ctrl/Cmd+F is taken only when the focus is not inside another dialog that does not contain the viewer, so the command palette (or any modal above the diff) keeps the key and its typing.
  • scripts/diff-find-demo-regression.ts: on desktop, the run now opens the palette over src/money.ts (Ctrl/Cmd+Shift+K), presses Ctrl/Cmd+F, types amount, and asserts the palette's input holds amount while the diff's Find stays closed; Escape then closes the palette and the existing Find flow continues.

Verification:

  • With the fix: diff-find-demo-regression passes all 6 runs.
  • With the fix reverted (git apply -R): the run fails at the palette keeps what was typed, the reported symptom.
  • bun run check fast is green on b9f95d0.

Non-blocking notes left as they are: the test-only matchKey/line fields, the commented VirtualizedFileDiff cast, and Ctrl+F suppressing the browser's find without a patch (the viewer's rows are virtualized, so the browser's find could not reach them either).

devswha and others added 9 commits October 24, 2026 21:49
The diff viewer gets a Find bar of its own (its Search button, or Ctrl/Cmd+F
while it has the keyboard). It searches the loaded patch as logical lines
(src/lib/repoDiffFind.ts): added, removed and unchanged lines, an unchanged
line once on its new side, case-sensitive and literal, never the mounted rows.
A match on a folded line turns Fold context off, and the row is brought into
view by a bounded measured reveal like VirtualSource's, through split, wrap
and theme changes. The active row gets an accent ring (only its side in
split) and its text a CSS highlight; the count and the match's kind and line
are spoken. Enter/Shift+Enter step and wrap; Escape closes Find before the
viewer and returns the focus. A new file, comparison or patch drops the
results; without a patch Find is off and says so. No new endpoint or frame;
nothing is fetched to widen the search.

Checked with bun test ./src/lib/repoDiffFind.test.ts, the extended
scripts/repo-diff-browser-qa.ts under bun run check run --build (10 000-line
fixture: folded hits at the top, middle and end, both sides, split and wrap,
loading, refused, offline and watch-only patches), the new
scripts/diff-find-demo-regression.ts on the demo build (enrolled in
ci-browser.sh), and bun run check fast.
The count and the active match's place sat flush against Previous, whose
focus ring is drawn outside the button, so the ring touched the text. The
count now keeps a space step before the buttons. The repository diff
browser check draws its phone runs at a phone's pixel ratio (3), so its
captures read as a phone's.

Checked with CHECK_WAIT_SECONDS=3600 bun run check run --build bun
scripts/repo-diff-browser-qa.ts and bun scripts/diff-find-demo-regression.ts.
On a phone, closing the Files sheet goes Back in history; the diff opened
right after it could be closed again by that late traversal. The find
comparison checks now open their diffs over the open list, as a row does,
and close the list at the end.

Checked with CHECK_WAIT_SECONDS=3600 bun run check run --build bun
scripts/repo-diff-browser-qa.ts, three passes in a row.
On a touch screen the find query was 34px tall beside 44px buttons. It now
takes the same touch-target height as the viewer's actions.

Checked with bun run check fast, bun scripts/diff-find-demo-regression.ts and
CHECK_WAIT_SECONDS=3600 bun run check run --build bun
scripts/repo-diff-browser-qa.ts, and by measuring the field at 390px.
A match past the right edge of an unwrapped row is scrolled into view in
its side's horizontal scroller. A repeated Ctrl/Cmd+F keeps the control
that first opened Find as the focus return, and reopening Find shows the
kept query's count and active match again. The bar's own words are read
at the body size (the reading size on a phone), its name stays visible
beside the query, its buttons keep an 8px gap, and the Korean scope hint
keeps each predicate on one line.
Opening Find over the Show text fallback counted matches in rows that were not mounted. It now returns to the diff, whose rows Find marks.
…ares them

The diff find bar reuses Previous match, Next match, Close search, No matches and the count from the terminal find bar, so they leave the terminal part for the base dictionary.
With the command palette open over the diff, Ctrl/Cmd+F opened Find underneath and the typing went to its query. The viewer now takes the shortcut only when the focus is not in another dialog, and the demo regression covers the palette over the diff.
@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: approved, but held for a recount. The PR CI's Fast checks fail in scripts/ci-browser.test.ts: expected 83, received 84. Main gained a browser-lane script (#1828) after this branch was cut, so with this PR's script the lane now holds one more than the count says. Rebase onto main and set the count to cover every script. The merge pass checks that the rebase changed only that count, then merges. A rebase needs no new CodeRabbit review.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto main (now including #1828) and recounted the browser lane in 6031d81: scripts/ci-browser.test.ts expects 84 rows (main's 83 plus diff-find-demo-regression.ts). git range-diff against the previous head shows that count as the only change; the other eight commits are identical. bun run check fast is green on 6031d81.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review-work report. Overall: PASSED.

Lane Verdict Confidence
QA (the code-review agent's matrix plus the merge pass's rerun; artifacts kept) PASS at b9f95d0 -
Code review (omo-native-code-reviewer, programming and remove-ai-slops) PASS (WATCH) -
Gate round 1 (9b9f49c) REJECT: Ctrl/Cmd+F took over while the command palette had focus HIGH
Gate round 2 (b9f95d0) APPROVE HIGH
Rebase onto main (6031d81) the PR's own diff changes only in the browser lane's script count in scripts/ci-browser.test.ts; the merge pass also checks the count on today's main right before merging -

QA

  • The unit tests and the typecheck pass.
  • diff-find-demo-regression passes all 6 runs, and repo-diff-browser-qa exits 0 with 12 Find checks across 4 viewports.
  • Both mutants are caught: overlapping matches and an ignored case.
  • At the 1 MiB patch limit, the worst query takes 27.6 ms per keystroke.

Behaviour

  • Find is literal and case-sensitive. It covers folded and unmounted rows and reveals the active match.
  • Escape closes Find first and returns focus.
  • Without a loaded patch, Find says why it can't search.
  • All locales are covered. The precedent is Zed's and VS Code's find bar.

Round 1 finding, fixed in b9f95d0: the viewer now leaves Ctrl/Cmd+F to a dialog above it. In the gate's browser run, the palette kept its focus and text, and Find still opened from the viewer, from the page body, and with the viewer inside a modal. Settings and other modals keep their keys. Without the guard, the new regression step fails at diff-find-demo-regression.ts:123.

Follow-ups (MINOR)

  • Some production code is used only by tests (matchKey, oldLine/newLine).
  • There is an as unknown as cast.
  • Ctrl+F still blocks the browser's own find when there is no patch.

All required checks are green, and no review thread is open.

CodeRabbit did not review this PR (rate-limited or skipped). The reviews above stand in for it.

@devswha
devswha merged commit 54b4db3 into main Oct 24, 2026
9 checks passed
@devswha
devswha deleted the feat/diff-find branch October 24, 2026 14:29
devswha added a commit that referenced this pull request Oct 24, 2026
… a pinned count (#1874)

## What
`scripts/ci-browser.test.ts` pinned the number of browser scripts
(`toHaveLength(83)`), a list of `toContain` lines and the last script.
So every PR that adds a browser script edited the same lines, and
parallel PRs conflicted on them just for that (#1831, #1837, #1849 and
#1852 needed rebases for it). This PR removes those pins and checks the
same things against the files on disk:

- The serial lane's summary must equal `scripts/demo-build.ts` followed
by the list parsed from `scripts/ci-browser.sh`
(`serialBrowserScripts()`), in order. This checks more than the old
count did.
- The lane must not repeat a script or name one that does not exist.
- Every `scripts/*-regression.ts` and `scripts/*-browser-qa.ts` must be
run by the lane in one of three ways: it has its own `run_script` line;
it is imported by a script the lane runs (transitively, e.g. through
`ui-regression.ts` or `ui-contexts-checks.ts`); or it is spawned by one
(`join(import.meta.dir, "x.ts")`). Spawns are followed only from files
that run as scripts, not from imported helpers, because those spawns sit
under `import.meta.main`. A script CI does not run has to be named in a
new `MANUAL_BROWSER_SCRIPTS` list. Today that list holds 13 scripts that
are run by hand (Android emulator, SSH fixture, native Windows, update
QA, ...).
- The manual list must only name scripts that exist and that CI does not
reach, so it cannot go stale.

A PR that adds a browser script now adds only its `run_script` line in
`scripts/ci-browser.sh` (or a line in the manual list), so two such PRs
no longer touch the same line. `docs/development.md` describes the
check.

Test-only change: CI behaviour is unchanged.

## Verification
- `bun test scripts/ci-browser.test.ts`: 7 pass.
- Mutation checks, each restored afterwards:
- Deleting the `run_script scripts/workspace-rows-regression.ts` line
fails "runs every browser script on disk ..." and lists that script as
unassigned.
- Adding `run_script scripts/does-not-exist-regression.ts` fails "runs
each script once, and only scripts that exist".
- Adding an untracked `scripts/brand-new-regression.ts` fails the
assignment check.
  - The restored tree passes.
- `bun run check fast`: green (typecheck, build, 6396 unit tests).
- Reviewed by a code-review agent. Its one HIGH finding (a spawn inside
an imported helper's `import.meta.main` block was being counted as run
by CI, hiding `keyboard-viewport-demo-regression.ts`) is fixed in this
commit.

---------

Co-authored-by: mp <mp@local>
devswha added a commit that referenced this pull request Oct 28, 2026
…the view (#2156)

## What this does for the user

Find in a diff now brings the match itself into view when its row is a
wrapped line taller than the screen, such as a long line on a phone with
wrapping on. Before, the viewer centred the whole row, so a match near
the end of a very long line could stay below the screen (#1602, the
follow-up left from #1849).

## How

`RepoDiff.tsx`'s reveal (`settle()`) measures the active row as before;
when that row is taller than the view, it centres the match's own text
range (the same `textRange` the highlight paints) instead of the row.
Every other row is unchanged: a row that fits is still centred whole, an
unwrapped row is still scrolled across first, and an unmounted row still
goes to the package's estimate first. Precedent: an editor's find (Zed,
VS Code) scrolls to the match, not to the line holding it; DESIGN.md's
Find in diff entry says so.

The diff-find demo regression (`scripts/diff-find-demo-regression.ts`),
the issue's other open note, now takes its screenshots at fixed moments:
its clock is Playwright's, run past the demo's one-shot turn completion
(4.5 s after load), and each shot waits for finite animations (a closed
sheet's drop, `lib/sheets.ts`) and ends running transitions first, as
`terminal-keyboard-demo-regression.ts` does. Two runs back to back: 58
of 66 shots byte-identical, the other 8 differ by at most 5 grey levels
on at most 183 pixels (rasterizer noise); before, 31 differed by state
(a sheet mid-slide, a hover mid-fade).

Fixes #1602

## How it was verified

- `scripts/repo-diff-browser-qa.ts` gains a wrapped unchanged line
taller than any view in the long-line fixture, its match at the very
end, and asserts the painted match lies inside the scroll view. On main
it fails: `row {top:-205,bottom:1271}, match {top:1254,bottom:1270},
view {top:269,bottom:798}`. With the fix it passes at 1440 and 390, dark
and light, with the rest of the script.
- `scripts/diff-find-demo-regression.ts` passes (all six
widths/themes/languages), twice.
- `bun run check fast`: typecheck, build, 7885 unit tests, 0 failures.
- Reviewed by omo-native-code-reviewer (APPROVE, three LOW notes: none
actionable) and Codex Sol 6.1 Fast xhigh (PASS). The demo screenshot
wait (second commit, test-only) came after those reviews.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant