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
This commit is contained in:
dualfroz committed 2026-10-03 02:02:28 +02:00
1 parent a0a55b30d3
commit 40b12a4e6c
3 files changed
+56 -2

No files matched your search

+1 -1
View File
@@ -94,7 +94,7 @@
},
},
{
"context": "BufferSearchBar",
"context": "BufferSearchBar && !in_replace > Editor",
"bindings": {
"shift-enter": "search::SelectPreviousMatch",
},
+1 -1
View File
@@ -93,7 +93,7 @@
},
},
{
"context": "BufferSearchBar",
"context": "BufferSearchBar && !in_replace > Editor",
"bindings": {
"shift-enter": "search::SelectPreviousMatch",
},
+54
View File
@@ -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);