iTerm2 icon indicating copy to clipboard operation
iTerm2 copied to clipboard

Add debounce to status bar search and filter components

Open kud opened this issue 1 month ago • 2 comments

Problem

When typing in the status bar search or filter components, the search/filter operations trigger immediately on every keystroke. This causes a flickering/blinking effect as the results update in real-time, which creates visual noise and can be distracting.

Solution

Added a 300ms debounce delay to both components:

  • MiniFilterViewController (Swift): Debounces filter query changes
  • iTermMiniSearchFieldViewController (Objective-C): Debounces search query changes

Changes

  • Added debounceTimer property to both view controllers
  • Modified controlTextDidChange methods to invalidate previous timers and schedule new ones
  • Search/filter operations now wait 300ms after the last keystroke before executing

Benefits

  • Eliminates flickering/blinking effect while typing
  • Reduces unnecessary search/filter operations
  • Improves overall user experience and performance
  • Makes the UI feel more polished and responsive

Testing

Manually tested both search and filter components by typing rapidly and verifying that:

  • Results only update after stopping typing for 300ms
  • No flickering occurs during typing
  • Functionality remains intact

kud avatar Nov 26 '25 23:11 kud

Search is already debounced using the algorithm in iTermFindDriver.m (see line 291). I think it makes sense to also debounce Filter, but it should use the same algorithm. Probably the debouncing algorithm should be factored out into its own class which can then be shared by iTermFindDriver and AsyncFilter.

gnachman avatar Dec 01 '25 05:12 gnachman

Good catch! This was an unintentional behavior change. The original code had a !self.viewController.view.isHidden check in startDelay that was lost during the refactoring.

I've restored this check in the debouncer callback to preserve the original behavior - searches will only execute when the view is visible.

Fixed in ca0da73

kud avatar Dec 03 '25 22:12 kud