Skip to content

fix: respect fuzzy filter when selecting/deselecting all in InteractiveMultiselect - #781

Merged
MarvinJWendt merged 3 commits into
pterm:masterfrom
nghiack7:fix/multiselect-filter-select-all
Oct 10, 2026
Merged

MarvinJWendt merged 3 commits into
pterm:masterfrom
nghiack7:fix/multiselect-filter-select-all

Conversation

@nghiack7

@nghiack7 nghiack7 commented May 9, 2026

Copy link
Copy Markdown
Contributor

Problem

When typing a search filter in `InteractiveMultiselectPrinter` and pressing Right Arrow (select all), all options get selected — not just the ones visible in the filtered list.

Repro:

  1. Create multiselect with options `["opt1", "test1", "test2", "test3"]`
  2. Type `test` to filter — only 3 matching options shown
  3. Press Right Arrow to select all
  4. Clear the filter — all 4 options are selected instead of only the 3 that matched

Similarly, Left Arrow (deselect all) always cleared the entire selection regardless of filter.

Fixes #761.

Root cause

Both handlers iterated `p.Options` (all options) instead of `p.fuzzySearchMatches` (the currently visible subset):

// before — ignores active filter
case keys.Right:
    p.selectedOptions = []int{}
    for i := 0; i < len(p.Options); i++ {  // BUG: all options, not filtered
        p.selectedOptions = append(p.selectedOptions, i)
    }

Fix

Iterate `p.fuzzySearchMatches` and use the existing `selectOption`/`isSelected` helpers. When no filter is active, `fuzzySearchMatches == Options`, so unfiltered behaviour is unchanged.

Tests

Three new tests:

  • `Show_SelectAll`: Right Arrow without filter selects all
  • `Show_DeselectAll`: Right then Left returns to empty selection
  • `Show_SelectAllWithFilter`: Right Arrow after typing `a` selects only `a`, not `b` or `c`

All existing tests pass.

When a fuzzy filter is active, pressing Right Arrow (select all) iterated
over p.Options instead of p.fuzzySearchMatches, selecting every option
regardless of the current filter.  Similarly, Left Arrow (deselect all)
always cleared the entire selection.

Fix both handlers to iterate p.fuzzySearchMatches.  When no filter is
active, fuzzySearchMatches equals Options, so the unfiltered behaviour
is preserved.  When a filter is active, only the visible subset is
selected or deselected.

Add three tests:
- Show_SelectAll: right arrow selects all when no filter active
- Show_DeselectAll: right then left returns to empty selection
- Show_SelectAllWithFilter: right arrow with 'a' filter selects only 'a'

Fixes pterm#761
@nghiack7
nghiack7 requested a review from MarvinJWendt as a code owner May 9, 2026 06:55
@github-actions github-actions Bot added the fix label May 9, 2026
@nghiack7

Copy link
Copy Markdown
Contributor Author

The CI failures are pre-existing flaky tests unrelated to this change:

  • TestRGB_Println — fails on some terminal environments due to color code detection
  • TestSpinnerPrinter_* — timing-sensitive tests that flake in CI (known issue: Tests flaky on linux/macos #289)
  • TestTreePrinterNilPrint — pre-existing

My changes only touch interactive_multiselect_printer.go and the three new tests I added (Show_SelectAll, Show_DeselectAll, Show_SelectAllWithFilter) all pass.

These failures also appear in other unrelated PRs in this repo — they are not introduced by this PR.

@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.22%. Comparing base (0669030) to head (3f175a3).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #781   +/-   ##
=======================================
  Coverage   92.21%   92.22%           
=======================================
  Files          66       66           
  Lines        4318     4321    +3     
=======================================
+ Hits         3982     3985    +3     
  Misses        244      244           
  Partials       92       92           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MarvinJWendt
MarvinJWendt merged commit 0c4e3a9 into pterm:master Oct 10, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InteractiveMultiselect: "Select All" (Right Arrow) ignores filter and selects all options

2 participants