Repository: mikaelmello/inquire (Rust)

Issue:
MultiSelect list doesn't show after filter is cleared on selection
**Describe the bug**
When using the `MultiSelect`, after a selection is made using the filter and the filter clears, the list doesn't reset. It requires the user to type and clear the filter manually to be able to see the whole list again.

**To Reproduce**
Steps to reproduce the behavior:
1. Implement a MultiSelect
2. Run your program
3. When you get to a `MultiSelect` Prompt, type in to filter the list
4. Select an item

**Expected behavior**
When the filter clears, the list should show all items again.

**Actual behavior**
Notice the filter clears, but the list doesn't reset. Typing in to filter the list again and deleting the filter manually then shows the whole list again.


**Screenshots**

1. Initial List
![image](https://github.com/mikaelmello/inquire/assets/1456302/f3e31620-0fa4-4cdb-bf48-d6a24b48b79c)

2. Filter the list
![image](https://github.com/mikaelmello/inquire/assets/1456302/2669a58a-0a0d-42ed-b7a3-78db33cb7339)

3. Select an item (filter clears, but list doesn't reset)
![image](https://github.com/mikaelmello/inquire/assets/1456302/f17fdfcf-2dea-4ffc-a61b-49f68cbb3da8)

4. Filter the list again
![image](https://github.com/mikaelmello/inquire/assets/1456302/eeecb42e-74c2-4fcd-967a-a67061c8bf52)

5. Backspace the filter to show the whole list again
![image](https://github.com/mikaelmello/inquire/assets/1456302/026e1e93-a911-46ff-b606-ed9340a87471)




Discussion:
Fixed on v0.7.4 :)

Thanks for reporting



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 069d20a0..5a7e4ddd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,9 @@
 
 ## [Unreleased] <!-- ReleaseDate -->
 
-- Fix unexpected behaviour of `keep_filter` option in MultiSelect prompts, where the resulting behaviour was the opposite of what was expected.
+- Fix unexpected behaviors of `keep_filter` option in MultiSelect prompts:
+  - Filter input is now correcly getting reset **only when** `keep_filter == false`.
+  - When the filter input is reset, the list of options is reset as well. Thanks @Swivelgames for reporting [#238](https://github.com/mikaelmello/inquire/issues/238).
 
 ## [0.7.3] - 2024-03-21
 
diff --git a/inquire/src/prompts/multiselect/prompt.rs b/inquire/src/prompts/multiselect/prompt.rs
index 956913b9..dc8d0838 100644
--- a/inquire/src/prompts/multiselect/prompt.rs
+++ b/inquire/src/prompts/multiselect/prompt.rs
@@ -148,11 +148,21 @@ where
             return ActionResult::Clean;
         }
 
+        let input_ref = match &mut self.input {
+            Some(input) => input,
+            None => return ActionResult::Clean,
+        };
+
+        if input_ref.is_empty() {
+            return ActionResult::Clean;
+        }
+
         match action {
             MultiSelectPromptAction::ToggleCurrentOption
             | MultiSelectPromptAction::SelectAll
             | MultiSelectPromptAction::ClearSelections => {
-                self.input.as_mut().map(Input::clear);
+                input_ref.clear();
+                self.run_scorer();
                 ActionResult::NeedsRedraw
             }
             _ => ActionResult::Clean,


Test patch:
diff --git a/inquire/src/prompts/multiselect/test.rs b/inquire/src/prompts/multiselect/test.rs
index dbbf95c0..6da41932 100644
--- a/inquire/src/prompts/multiselect/test.rs
+++ b/inquire/src/prompts/multiselect/test.rs
@@ -234,3 +234,24 @@ fn keep_filter_should_be_true_by_default() {
     let expected_answer = vec![ListOption::new(0, 1)];
     assert_eq!(expected_answer, ans);
 }
+
+#[test]
+// Anti-regression test: https://github.com/mikaelmello/inquire/issues/238
+fn keep_filter_false_should_reset_option_list() {
+    let mut backend = fake_backend(vec![
+        Key::Char('3', KeyModifiers::NONE), // filter to option 3
+        Key::Char(' ', KeyModifiers::NONE), // toggle option 3, filter input is reset
+        Key::Char(' ', KeyModifiers::NONE), // toggle option 1 after option list is reset
+        Key::Enter,
+    ]);
+
+    let options = vec![1, 2, 3, 4, 5];
+
+    let ans = MultiSelect::new("Question", options)
+        .with_keep_filter(false)
+        .prompt_with_backend(&mut backend)
+        .unwrap();
+
+    let expected_answer = vec![ListOption::new(0, 1), ListOption::new(2, 3)];
+    assert_eq!(expected_answer, ans);
+}