Skip to content

Keep n/N's place when the page changes while a repeated page search still runs - #5910

Merged
leaf-agent merged 1 commit into
mainfrom
nightly/repeat-search-landing
Nov 13, 2026
Merged

leaf-agent merged 1 commit into
mainfrom
nightly/repeat-search-landing

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

After Enter closes a page search and the page then changes, n or Shift+n searches again from the match it selected. On a page whose search outlasts its first 8 ms slice, a step back from the first match could lose that place: the next Shift+n stepped back to match 1 instead of coming round to the last match. This keeps the place, and a new browser test fails before the change and passes after it.

Cause. repeatSearch called find with a new query's landing ("the first match at or below the top of the window"), then cleared it. But find takes its first slice at once, and that slice can land before the clear. Landing with the field closed writes the match into the repeated search's position in take. The normal step overwrote that position again, but a step that stays put while the search runs (Shift+n from the first match, which says "Searching") kept the stray one.

Change. find now takes its landing as one optional argument. repeatSearch passes none, so the search it starts lands nowhere. That removes the stray landing, the line clearing it, and an index argument nothing read.

Test. test_a_step_back_after_the_page_changed_keeps_the_match_it_stood_on searches ten text documents, selects match 1 with Enter, scrolls it above the window and changes the page. It holds the page's zero-delay timers and lets the first slice take a dozen steps, so the search is still running when Shift+n says "Searching". Once the search ends, the next Shift+n must select the last match. On main it selects match 1. The test and the existing search and match tests in test_render_anchors.py (31) pass, and pre-commit and the browser type check pass.

#5875 introduced this; the nightly review of recent commits found it.

…runs

When the page changed after Enter, n or N searched again by calling find with a
landing for a new query, then cleared it. find takes its first slice at once,
so on a page whose search outlasts that slice, the slice could land on the
first match in the window and write it into the repeated search's position.
Where the step then stayed put (N from the first match, "Searching"), the
position kept that match, and the next N stepped back from it rather than
coming round to the last match.

find now takes its landing as one optional argument, and repeatSearch passes
none, so a repeated search lands nowhere and steps from where it stood. The
stray landing, the line clearing it and an index argument nothing read go.

Introduced by #5875. The new browser test fails before this change (the
second N selects match 1) and passes after.
@leaf-agent
leaf-agent merged commit 7acf9d5 into main Nov 13, 2026
6 checks passed
@leaf-agent
leaf-agent deleted the nightly/repeat-search-landing branch November 13, 2026 07:15
leaf-agent added a commit that referenced this pull request Nov 16, 2026
…h the held search before Shift+n (#6211)

Two tests failed in main's push run
[43928743834](https://github.com/max-sixty/leaf/actions/runs/43928743834)
(`3bc561561`). This PR fixes both, and changes only the tests.

- **`test_code_is_colored_without_a_word_moving`**: the test was stale
after #6191. That PR moved a docked `lf-note`'s line indent out of its
padding and into `margin-inline-start`, so the card keeps its
first-paint size. The card and its words still stand where they did, but
the note's border box now starts at the indent: 33.5px from the frame
for the example's 4-space line, where the test expected 1px. The test
now measures the note's margin box, which is what meets the frame (to
within 0.1px, since the indent is a fractional number of `ch`). It fails
on `main`. With #6191's `code.css` reverted, the old assertion passes.
-
**`test_a_step_back_after_the_page_changed_keeps_the_match_it_stood_on`**:
the test pressed before the page was ready. It released the held search
slices and pressed Shift+n at once. On a slow runner the search was
still going, so the step back stayed on the first match and said
"Searching", which is the behavior #5910 specified, and the wait for the
last match ran out at 120 s. The test now runs the held slices, and any
they schedule, until the search ends, and then presses. With `leaf-dev
suite flake --cpu-throttle 8`, it failed 4 of 18 copies before this
change and 0 of 18 after. It also passed 18 of 18 at throttle 16.

The other two failures in that run already have owners: #5642/#6130 and
#6139.

Not covered here: at throttle 8 to 16,
`test_code_is_colored_without_a_word_moving` also fails sometimes at an
earlier line. The test reads the `lf-code` token colours before
`bucket_key` is split into its own span. CI has not shown this failure,
and it happens with or without this change.

Refs #3985 — automated triage

Co-authored-by: leaf-agent <[email protected]>
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