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);