[PR #17092] Fix search highlights during reflow #31108

Open
opened 2026-01-31 09:45:11 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/17092

State: closed
Merged: Yes


This PR extends til::throttled_func to also support debouncing:

  • throttling: "At most 1 call every N seconds"
  • debouncing: "Exactly 1 call after N seconds of inactivity"

Based on the latter the following series of changes were made:

  • An OutputIdle event was added to ControlCore which is
    raised once there hasn't been any incoming data in 100ms.
    This also triggers an update of our regex patterns (URL detection).
  • The event is then caught by TermControl which calls Search().
  • Search() in turn was modified to return its results by-value
    as a struct, which avoids the need for a search-update event
    and simplifies how we update the UI.

This architectural change, most importantly the removal of the
TextLayoutUpdated event, fixes a DoS bug in Windows Terminal:
As the event leads to UI thread activity, printing lots of text
continuously results in the UI thread becoming unresponsive.

On top of these, a number of improvements were made:

  • IRenderEngine::InvalidateHighlight was changed to take the
    TextBuffer by-reference which avoids the need to accumulate the
    line renditions in a std::vector first. This improves Debug build
    performance during reflow by what I guess must be roughly
    a magnitude faster. This difference is very noticeable.
  • When closing the search box, ClearSearch() is called to remove
    the highlights. The search text is restored when it's reopened,
    however the current search position isn't.

Closes #17073
Closes #17089

Validation Steps Performed

  • UIA announcements:
    • Pressing Ctrl+Shift+F the first time does not lead to one
    • Typing the first letter does
    • Closing doesn't
    • Reopening does (as it restores the letter)
  • Closing the search box dismisses the highlights
  • Resizing the window recalculates the highlights
  • Changing the terminal output while the box is open
    recalculates the highlights
**Original Pull Request:** https://github.com/microsoft/terminal/pull/17092 **State:** closed **Merged:** Yes --- This PR extends `til::throttled_func` to also support debouncing: * throttling: "At most 1 call every N seconds" * debouncing: "Exactly 1 call after N seconds of inactivity" Based on the latter the following series of changes were made: * An `OutputIdle` event was added to `ControlCore` which is raised once there hasn't been any incoming data in 100ms. This also triggers an update of our regex patterns (URL detection). * The event is then caught by `TermControl` which calls `Search()`. * `Search()` in turn was modified to return its results by-value as a struct, which avoids the need for a search-update event and simplifies how we update the UI. This architectural change, most importantly the removal of the `TextLayoutUpdated` event, fixes a DoS bug in Windows Terminal: As the event leads to UI thread activity, printing lots of text continuously results in the UI thread becoming unresponsive. On top of these, a number of improvements were made: * `IRenderEngine::InvalidateHighlight` was changed to take the `TextBuffer` by-reference which avoids the need to accumulate the line renditions in a `std::vector` first. This improves Debug build performance during reflow by what I guess must be roughly a magnitude faster. This difference is very noticeable. * When closing the search box, `ClearSearch()` is called to remove the highlights. The search text is restored when it's reopened, however the current search position isn't. Closes #17073 Closes #17089 ## Validation Steps Performed * UIA announcements: * Pressing Ctrl+Shift+F the first time does not lead to one ✅ * Typing the first letter does ✅ * Closing doesn't ✅ * Reopening does (as it restores the letter) ✅ * Closing the search box dismisses the highlights ✅ * Resizing the window recalculates the highlights ✅ * Changing the terminal output while the box is open recalculates the highlights ✅
claunia added the pull-request label 2026-01-31 09:45:11 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31108