fix(multiselect): enforce selection limit while filtering
The toggle handler's limit guard indexed the unfiltered options slice with the cursor, but the cursor tracks the filtered slice. When a filter was applied the two indices diverged, so the guard inspected the wrong option's selected state and allowed toggling past the configured Limit. Index the option that is actually being toggled instead, and add a regression test that selects up to the limit, filters, then verifies a further toggle is a no-op.
This commit is contained in:
1 parent
bb7e934525
commit
ba0822d4e9
2 files changed
+42
-1
No files matched your search
@@ -423,7 +423,7 @@ func (m *MultiSelect[T]) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||
case key.Matches(msg, m.keymap.Toggle) && !m.filtering:
|
||||
for i, option := range m.options.val {
|
||||
if option.Key == m.filteredOptions[m.cursor].Key {
|
||||
if !m.options.val[m.cursor].selected && m.limit > 0 && m.numSelected() >= m.limit {
|
||||
if !m.options.val[i].selected && m.limit > 0 && m.numSelected() >= m.limit {
|
||||
break
|
||||
}
|
||||
selected := m.options.val[i].selected
|
||||
|
||||
Reference in new issue
Block a user