From 40b12a4e6c366e2b09a3056413d95aa36f291798 Mon Sep 17 00:00:00 2001 From: DualFroz Date: Sat, 3 Oct 2026 02:02:28 +0200 Subject: [PATCH] Fix shift-enter in buffer search with the JetBrains keymap With the JetBrains base keymap, shift-enter in the buffer search query inserted a newline instead of going to the previous match. The keymap binds shift-enter to `editor::Newline` for auto-height editors, which matches at the editor's depth, while its search bar binding only matched at the `BufferSearchBar` level and lost to it. The default keymap's `BufferSearchBar && !in_replace > Editor` binding loses too, since base keymaps are loaded after it. Bind it on the query editor itself, like the default keymaps and the thread search binding right below it do, so it wins by coming later in the same file. Closes #62696 --- assets/keymaps/linux/jetbrains.json | 2 +- assets/keymaps/macos/jetbrains.json | 2 +- crates/search/src/buffer_search.rs | 54 +++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/assets/keymaps/linux/jetbrains.json b/assets/keymaps/linux/jetbrains.json index 40a66ab..183fade 100644 --- a/assets/keymaps/linux/jetbrains.json +++ b/assets/keymaps/linux/jetbrains.json @@ -94,7 +94,7 @@ }, }, { - "context": "BufferSearchBar", + "context": "BufferSearchBar && !in_replace > Editor", "bindings": { "shift-enter": "search::SelectPreviousMatch", }, diff --git a/assets/keymaps/macos/jetbrains.json b/assets/keymaps/macos/jetbrains.json index 8eadc80..176663f 100644 --- a/assets/keymaps/macos/jetbrains.json +++ b/assets/keymaps/macos/jetbrains.json @@ -93,7 +93,7 @@ }, }, { - "context": "BufferSearchBar", + "context": "BufferSearchBar && !in_replace > Editor", "bindings": { "shift-enter": "search::SelectPreviousMatch", }, diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index 8726f97..fac502c 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -3301,6 +3301,60 @@ mod tests { }); } + #[gpui::test] + async fn test_shift_enter_selects_previous_match_with_jetbrains_keymap( + cx: &mut TestAppContext, + ) { + let (_editor, search_bar, cx) = init_test(cx); + + search_bar + .update_in(cx, |search_bar, window, cx| { + search_bar.search("or", None, true, window, cx) + }) + .await + .unwrap(); + search_bar.update_in(cx, |search_bar, window, cx| { + assert_eq!(search_bar.active_match_index, Some(0)); + window.focus(&search_bar.query_editor.focus_handle(cx), cx); + }); + cx.run_until_parked(); + + // The JetBrains keymaps bind shift-enter to a newline in auto-height + // editors, which must not win over the search bar's own binding. + for (default_keymap, jetbrains_keymap, expected_match_index) in [ + ( + "keymaps/default-linux.json", + "keymaps/linux/jetbrains.json", + 6, + ), + ( + "keymaps/default-macos.json", + "keymaps/macos/jetbrains.json", + 5, + ), + ] { + cx.update(|_, cx| { + cx.clear_key_bindings(); + for keymap in [default_keymap, jetbrains_keymap] { + cx.bind_keys( + settings::KeymapFile::load_asset_allow_partial_failure(keymap, cx).unwrap(), + ); + } + }); + + cx.simulate_keystrokes("shift-enter"); + + search_bar.read_with(cx, |search_bar, cx| { + assert_eq!(search_bar.query(cx), "or", "with {jetbrains_keymap}"); + assert_eq!( + search_bar.active_match_index, + Some(expected_match_index), + "with {jetbrains_keymap}" + ); + }); + } + } + #[gpui::test] async fn test_toggle_soft_wrap_relays_to_searched_editor(cx: &mut TestAppContext) { init_globals(cx);