Keep selection in SwitchToHelixNormalMode (#41583)

Closes #41125

Release Notes:

- Fixed `SwitchToHelixNormalMode` to keep selection
- Added default keybinds for `SwitchToHelixNormalMode` when in Helix
mode
This commit is contained in:
Andrew Farkas
2025-10-31 01:53:46 +00:00
committed by GitHub
parent c2537fad43
commit eab06eb1d9
16 changed files with 182 additions and 74 deletions
+14 -7
View File
@@ -10,8 +10,9 @@ use any_vec::AnyVec;
use anyhow::Context as _;
use collections::HashMap;
use editor::{
DisplayPoint, Editor, EditorSettings,
DisplayPoint, Editor, EditorSettings, VimFlavor,
actions::{Backtab, Tab},
vim_flavor,
};
use futures::channel::oneshot;
use gpui::{
@@ -825,7 +826,8 @@ impl BufferSearchBar {
.searchable_items_with_matches
.get(&active_searchable_item.downgrade())
{
active_searchable_item.activate_match(match_ix, matches, window, cx)
let collapse = editor::vim_flavor(cx) == Some(VimFlavor::Vim);
active_searchable_item.activate_match(match_ix, matches, collapse, window, cx)
}
}
@@ -970,7 +972,8 @@ impl BufferSearchBar {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.select_match(Direction::Next, 1, window, cx);
let collapse = vim_flavor(cx) == Some(VimFlavor::Vim);
self.select_match(Direction::Next, 1, collapse, window, cx);
}
fn select_prev_match(
@@ -979,7 +982,8 @@ impl BufferSearchBar {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.select_match(Direction::Prev, 1, window, cx);
let collapse = vim_flavor(cx) == Some(VimFlavor::Vim);
self.select_match(Direction::Prev, 1, collapse, window, cx);
}
pub fn select_all_matches(
@@ -1004,6 +1008,7 @@ impl BufferSearchBar {
&mut self,
direction: Direction,
count: usize,
collapse: bool,
window: &mut Window,
cx: &mut Context<Self>,
) {
@@ -1026,7 +1031,7 @@ impl BufferSearchBar {
.match_index_for_direction(matches, index, direction, count, window, cx);
searchable_item.update_matches(matches, window, cx);
searchable_item.activate_match(new_match_index, matches, window, cx);
searchable_item.activate_match(new_match_index, matches, collapse, window, cx);
}
}
@@ -1040,7 +1045,8 @@ impl BufferSearchBar {
return;
}
searchable_item.update_matches(matches, window, cx);
searchable_item.activate_match(0, matches, window, cx);
let collapse = vim_flavor(cx) == Some(VimFlavor::Vim);
searchable_item.activate_match(0, matches, collapse, window, cx);
}
}
@@ -1055,7 +1061,8 @@ impl BufferSearchBar {
}
let new_match_index = matches.len() - 1;
searchable_item.update_matches(matches, window, cx);
searchable_item.activate_match(new_match_index, matches, window, cx);
let collapse = vim_flavor(cx) == Some(VimFlavor::Vim);
searchable_item.activate_match(new_match_index, matches, collapse, window, cx);
}
}
+6 -4
View File
@@ -9,10 +9,10 @@ use anyhow::Context as _;
use collections::HashMap;
use editor::{
Anchor, Editor, EditorEvent, EditorSettings, MAX_TAB_TITLE_LEN, MultiBuffer, PathKey,
SelectionEffects,
SelectionEffects, VimFlavor,
actions::{Backtab, SelectAll, Tab},
items::active_match_index,
multibuffer_context_lines,
multibuffer_context_lines, vim_flavor,
};
use futures::{StreamExt, stream::FuturesOrdered};
use gpui::{
@@ -1344,7 +1344,8 @@ impl ProjectSearchView {
let range_to_select = match_ranges[new_index].clone();
self.results_editor.update(cx, |editor, cx| {
let range_to_select = editor.range_for_match(&range_to_select);
let collapse = vim_flavor(cx) == Some(VimFlavor::Vim);
let range_to_select = editor.range_for_match(&range_to_select, collapse);
editor.unfold_ranges(std::slice::from_ref(&range_to_select), false, true, cx);
editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges([range_to_select])
@@ -1415,9 +1416,10 @@ impl ProjectSearchView {
let is_new_search = self.search_id != prev_search_id;
self.results_editor.update(cx, |editor, cx| {
if is_new_search {
let collapse = vim_flavor(cx) == Some(VimFlavor::Vim);
let range_to_select = match_ranges
.first()
.map(|range| editor.range_for_match(range));
.map(|range| editor.range_for_match(range, collapse));
editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(range_to_select)
});