Skip to content

Comments

Fix tab activation regression in search highlighting#14089

Open
cderv wants to merge 1 commit intofeature/robust-search-highlightingfrom
fix/search-tabset-activation-regression
Open

Fix tab activation regression in search highlighting#14089
cderv wants to merge 1 commit intofeature/robust-search-highlightingfrom
fix/search-tabset-activation-regression

Conversation

@cderv
Copy link
Collaborator

@cderv cderv commented Feb 23, 2026

Important

This PR targets the feature/robust-search-highlighting branch (#14080), not main. It is intended to be merged into #14080 before that PR merges into main.

Context

PR #14080 replaced activateTabsWithMatches() (from #14053) with openAllTabsetsContainingEl(), which is a much cleaner approach — 9 lines vs 65 — but dropped two behaviors that the playwright tests in html-search-tabsets.spec.ts verify.

What regressed

  1. "Keep active tab" logic — when multiple panes in the same tabset contain a match, the old code kept the already-active tab. The new code unconditionally activated each pane, so the last match processed won.

  2. Pageshow timing — tab activation ran during DOMContentLoaded, but tabsets.js restores tab state from localStorage on pageshow (which fires after). So localStorage overwrote search activation.

Fix

Adapt openAllTabsetsContainingEl (not replace it) with minimal changes:

  • Before activating a pane, check if the same tabset's active pane already has a <mark> — skip if so
  • Move tab activation from inside highlight() to a pageshow handler, so it runs after tabsets.js
  • Add scrollToFirstVisibleMatch that skips marks inside inactive tab panes
  • Fix for (leaf of leafNodes)for (const leaf of leafNodes) (implicit global)

The adapted function stays at 9 lines (vs the 65-line activateTabsWithMatches it replaced). highlight() is simplified to marking-only.

Test

All 6 tests × 3 browsers pass locally:

Running 18 tests using 11 workers
  18 passed (16.3s)

…w timing

Adapt openAllTabsetsContainingEl to:
- Skip tab activation when the active pane already contains a match
- Defer tab activation to pageshow so it runs after tabsets.js restores
  localStorage state (search activation wins over stored preference)
- Scroll to first visible match after tab activation settles
- Fix implicit global variable (const leaf)
@cderv cderv requested a review from vezwork February 23, 2026 15:08
@posit-snyk-bot
Copy link
Collaborator

posit-snyk-bot commented Feb 23, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

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.

2 participants