Skip to content

fix(search): skip full buffer scan when term is incremental extension#5866

Open
Poonam1216 wants to merge 1 commit into
xtermjs:masterfrom
Poonam1216:fix/incremental-search-highlighting
Open

fix(search): skip full buffer scan when term is incremental extension#5866
Poonam1216 wants to merge 1 commit into
xtermjs:masterfrom
Poonam1216:fix/incremental-search-highlighting

Conversation

@Poonam1216

Copy link
Copy Markdown

Problem

Every keystroke during search triggers a full buffer scan from row 0,
even when the user is just adding characters (e.g. "hel" → "hell").
This causes the 2.5s+ input delay shown in issue #5176 profile.

Solution

When the new term is a plain-text extension of the cached term, filter
the existing results array instead of re-scanning the buffer.

  • Add isIncrementalExtension() to SearchState
  • In _highlightAllMatches(), filter existing results when incremental
    extension is detected
  • Regex and wholeWord searches still trigger full scan (correct behavior)

Fixes #5177

When a user types incrementally (e.g. 'hel' → 'hell'), filter existing
results instead of re-scanning the entire terminal buffer. This avoids
redundant work and improves search responsiveness.

- Add isIncrementalExtension() to SearchState to detect when new term
  extends the cached term
- In _highlightAllMatches(), filter existing results when incremental
  extension is detected instead of doing a full search
- Skip optimization for regex and wholeWord searches where filtering
  existing results would be incorrect

Fixes xtermjs#5177
@Poonam1216 Poonam1216 force-pushed the fix/incremental-search-highlighting branch from fe1ce47 to e3c46cb Compare May 4, 2026 17:18
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.

Search is not incremental

1 participant