Repository: jesseduffield/lazygit (language: go)

Issue:
View filtering: pressing `<esc>` exits whole `Keybindings` instead of just filter mode
**Describe the bug**
When trying to exit filter mode in `Keybindings` (or `Recent repositories`) using `<esc>` (as the "tooltip" at the bottom suggests), the whole view is closed instead of just the filter mode.

**To Reproduce**
Steps to reproduce the behavior:
1. Open for example `Keybindings` via `?`.
2. Start filtering with `/`, enter and accept some filter pattern.
3. There is a tooltip at the bottom: _\<esc\>: Exit filter mode_
4. Pressing `<esc>` exits the `Keybindings` view, not just the filter mode

**Screenshots**
![2023-07-20_13-59](https://github.com/jesseduffield/lazygit/assets/19737748/51efb0b2-5c39-498c-89d1-d4f05354ed2a)

**Version info:**
```
$ lazygit --version 
commit=1f920ae6b, build date=20230720.112057, build source=unknown, version=pre-release-0.39-2.1f920ae6b, os=linux, arch=amd64, git version=2.41.0
```


Discussion / hints:
Ah damnit and right after cutting a new release! haha. Alright we'll need to push a fix for this soon

Fix patch:
diff --git a/pkg/gui/controllers/menu_controller.go b/pkg/gui/controllers/menu_controller.go
index c9ba2c701e7..108bd9cf733 100644
--- a/pkg/gui/controllers/menu_controller.go
+++ b/pkg/gui/controllers/menu_controller.go
@@ -65,6 +65,11 @@ func (self *MenuController) press() error {
 }
 
 func (self *MenuController) close() error {
+	if self.context().IsFiltering() {
+		self.c.Helpers().Search.Cancel()
+		return nil
+	}
+
 	return self.c.PopContext()
 }
 


Test patch:
diff --git a/pkg/integration/tests/filter_and_search/filter_menu_cancel_filter_with_escape.go b/pkg/integration/tests/filter_and_search/filter_menu_cancel_filter_with_escape.go
new file mode 100644
index 00000000000..8c84e1827de
--- /dev/null
+++ b/pkg/integration/tests/filter_and_search/filter_menu_cancel_filter_with_escape.go
@@ -0,0 +1,36 @@
+package filter_and_search
+
+import (
+	"github.com/jesseduffield/lazygit/pkg/config"
+	. "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var FilterMenuCancelFilterWithEscape = NewIntegrationTest(NewIntegrationTestArgs{
+	Description:  "Filtering the keybindings menu, then pressing esc to turn off the filter",
+	ExtraCmdArgs: []string{},
+	Skip:         false,
+	SetupConfig:  func(config *config.AppConfig) {},
+	SetupRepo:    func(shell *Shell) {},
+	Run: func(t *TestDriver, keys config.KeybindingConfig) {
+		t.Views().Files().IsFocused().
+			Press(keys.Universal.OptionMenu)
+
+		t.ExpectPopup().Menu().
+			Title(Equals("Keybindings")).
+			Filter("Toggle staged").
+			Lines(
+				// menu has filtered down to the one item that matches the filter
+				Contains(`Toggle staged`).IsSelected(),
+			)
+
+		// Escape should cancel the filter, not close the menu
+		t.GlobalPress(keys.Universal.Return)
+		t.ExpectPopup().Menu().
+			Title(Equals("Keybindings")).
+			LineCount(GreaterThan(1))
+
+		// Another escape closes the menu
+		t.GlobalPress(keys.Universal.Return)
+		t.Views().Files().IsFocused()
+	},
+})
diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go
index 0a50b74416d..c669bbae391 100644
--- a/pkg/integration/tests/test_list.go
+++ b/pkg/integration/tests/test_list.go
@@ -122,6 +122,7 @@ var tests = []*components.IntegrationTest{
 	filter_and_search.FilterFiles,
 	filter_and_search.FilterFuzzy,
 	filter_and_search.FilterMenu,
+	filter_and_search.FilterMenuCancelFilterWithEscape,
 	filter_and_search.FilterRemoteBranches,
 	filter_and_search.NestedFilter,
 	filter_and_search.NestedFilterTransient,