Skip to content

Commit 6bf5e92

Browse files
authored
Revert "Keep selection in SwitchToHelixNormalMode (#41583)" (#42892)
Closes #ISSUE Release Notes: - Fixes vim "go to definition" making a selection
1 parent 46ad6c0 commit 6bf5e92

File tree

18 files changed

+94
-183
lines changed

18 files changed

+94
-183
lines changed

assets/keymaps/vim.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,6 @@
421421
"ctrl-[": "editor::Cancel"
422422
}
423423
},
424-
{
425-
"context": "vim_mode == helix_select && !menu",
426-
"bindings": {
427-
"escape": "vim::SwitchToHelixNormalMode"
428-
}
429-
},
430424
{
431425
"context": "(vim_mode == helix_normal || vim_mode == helix_select) && !menu",
432426
"bindings": {

crates/agent_ui/src/text_thread_editor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,12 +2626,11 @@ impl SearchableItem for TextThreadEditor {
26262626
&mut self,
26272627
index: usize,
26282628
matches: &[Self::Match],
2629-
collapse: bool,
26302629
window: &mut Window,
26312630
cx: &mut Context<Self>,
26322631
) {
26332632
self.editor.update(cx, |editor, cx| {
2634-
editor.activate_match(index, matches, collapse, window, cx);
2633+
editor.activate_match(index, matches, window, cx);
26352634
});
26362635
}
26372636

crates/debugger_tools/src/dap_log.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,13 +1029,11 @@ impl SearchableItem for DapLogView {
10291029
&mut self,
10301030
index: usize,
10311031
matches: &[Self::Match],
1032-
collapse: bool,
10331032
window: &mut Window,
10341033
cx: &mut Context<Self>,
10351034
) {
1036-
self.editor.update(cx, |e, cx| {
1037-
e.activate_match(index, matches, collapse, window, cx)
1038-
})
1035+
self.editor
1036+
.update(cx, |e, cx| e.activate_match(index, matches, window, cx))
10391037
}
10401038

10411039
fn select_matches(

crates/editor/src/editor.rs

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ pub struct Editor {
10991099
searchable: bool,
11001100
cursor_shape: CursorShape,
11011101
current_line_highlight: Option<CurrentLineHighlight>,
1102+
collapse_matches: bool,
11021103
autoindent_mode: Option<AutoindentMode>,
11031104
workspace: Option<(WeakEntity<Workspace>, Option<WorkspaceId>)>,
11041105
input_enabled: bool,
@@ -2211,7 +2212,7 @@ impl Editor {
22112212
.unwrap_or_default(),
22122213
current_line_highlight: None,
22132214
autoindent_mode: Some(AutoindentMode::EachLine),
2214-
2215+
collapse_matches: false,
22152216
workspace: None,
22162217
input_enabled: !is_minimap,
22172218
use_modal_editing: full_mode,
@@ -2384,7 +2385,10 @@ impl Editor {
23842385
}
23852386
}
23862387
EditorEvent::Edited { .. } => {
2387-
if vim_flavor(cx).is_none() {
2388+
let vim_mode = vim_mode_setting::VimModeSetting::try_get(cx)
2389+
.map(|vim_mode| vim_mode.0)
2390+
.unwrap_or(false);
2391+
if !vim_mode {
23882392
let display_map = editor.display_snapshot(cx);
23892393
let selections = editor.selections.all_adjusted_display(&display_map);
23902394
let pop_state = editor
@@ -3013,12 +3017,12 @@ impl Editor {
30133017
self.current_line_highlight = current_line_highlight;
30143018
}
30153019

3016-
pub fn range_for_match<T: std::marker::Copy>(
3017-
&self,
3018-
range: &Range<T>,
3019-
collapse: bool,
3020-
) -> Range<T> {
3021-
if collapse {
3020+
pub fn set_collapse_matches(&mut self, collapse_matches: bool) {
3021+
self.collapse_matches = collapse_matches;
3022+
}
3023+
3024+
pub fn range_for_match<T: std::marker::Copy>(&self, range: &Range<T>) -> Range<T> {
3025+
if self.collapse_matches {
30223026
return range.start..range.start;
30233027
}
30243028
range.clone()
@@ -16921,7 +16925,7 @@ impl Editor {
1692116925

1692216926
editor.update_in(cx, |editor, window, cx| {
1692316927
let range = target_range.to_point(target_buffer.read(cx));
16924-
let range = editor.range_for_match(&range, false);
16928+
let range = editor.range_for_match(&range);
1692516929
let range = collapse_multiline_range(range);
1692616930

1692716931
if !split
@@ -21761,7 +21765,9 @@ impl Editor {
2176121765
.and_then(|e| e.to_str())
2176221766
.map(|a| a.to_string()));
2176321767

21764-
let vim_mode = vim_flavor(cx).is_some();
21768+
let vim_mode = vim_mode_setting::VimModeSetting::try_get(cx)
21769+
.map(|vim_mode| vim_mode.0)
21770+
.unwrap_or(false);
2176521771

2176621772
let edit_predictions_provider = all_language_settings(file, cx).edit_predictions.provider;
2176721773
let copilot_enabled = edit_predictions_provider
@@ -22396,28 +22402,6 @@ fn edit_for_markdown_paste<'a>(
2239622402
(range, new_text)
2239722403
}
2239822404

22399-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
22400-
pub enum VimFlavor {
22401-
Vim,
22402-
Helix,
22403-
}
22404-
22405-
pub fn vim_flavor(cx: &App) -> Option<VimFlavor> {
22406-
if vim_mode_setting::HelixModeSetting::try_get(cx)
22407-
.map(|helix_mode| helix_mode.0)
22408-
.unwrap_or(false)
22409-
{
22410-
Some(VimFlavor::Helix)
22411-
} else if vim_mode_setting::VimModeSetting::try_get(cx)
22412-
.map(|vim_mode| vim_mode.0)
22413-
.unwrap_or(false)
22414-
{
22415-
Some(VimFlavor::Vim)
22416-
} else {
22417-
None // neither vim nor helix mode
22418-
}
22419-
}
22420-
2242122405
fn process_completion_for_edit(
2242222406
completion: &Completion,
2242322407
intent: CompletionIntent,

crates/editor/src/items.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,12 +1586,11 @@ impl SearchableItem for Editor {
15861586
&mut self,
15871587
index: usize,
15881588
matches: &[Range<Anchor>],
1589-
collapse: bool,
15901589
window: &mut Window,
15911590
cx: &mut Context<Self>,
15921591
) {
15931592
self.unfold_ranges(&[matches[index].clone()], false, true, cx);
1594-
let range = self.range_for_match(&matches[index], collapse);
1593+
let range = self.range_for_match(&matches[index]);
15951594
let autoscroll = if EditorSettings::get_global(cx).search.center_on_match {
15961595
Autoscroll::center()
15971596
} else {

crates/language_tools/src/lsp_log_view.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,13 +812,11 @@ impl SearchableItem for LspLogView {
812812
&mut self,
813813
index: usize,
814814
matches: &[Self::Match],
815-
collapse: bool,
816815
window: &mut Window,
817816
cx: &mut Context<Self>,
818817
) {
819-
self.editor.update(cx, |e, cx| {
820-
e.activate_match(index, matches, collapse, window, cx)
821-
})
818+
self.editor
819+
.update(cx, |e, cx| e.activate_match(index, matches, window, cx))
822820
}
823821

824822
fn select_matches(

crates/search/src/buffer_search.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use any_vec::AnyVec;
1010
use anyhow::Context as _;
1111
use collections::HashMap;
1212
use editor::{
13-
DisplayPoint, Editor, EditorSettings, VimFlavor,
13+
DisplayPoint, Editor, EditorSettings,
1414
actions::{Backtab, Tab},
15-
vim_flavor,
1615
};
1716
use futures::channel::oneshot;
1817
use gpui::{
@@ -828,8 +827,7 @@ impl BufferSearchBar {
828827
.searchable_items_with_matches
829828
.get(&active_searchable_item.downgrade())
830829
{
831-
let collapse = editor::vim_flavor(cx) == Some(VimFlavor::Vim);
832-
active_searchable_item.activate_match(match_ix, matches, collapse, window, cx)
830+
active_searchable_item.activate_match(match_ix, matches, window, cx)
833831
}
834832
}
835833

@@ -976,8 +974,7 @@ impl BufferSearchBar {
976974
window: &mut Window,
977975
cx: &mut Context<Self>,
978976
) {
979-
let collapse = vim_flavor(cx) == Some(VimFlavor::Vim);
980-
self.select_match(Direction::Next, 1, collapse, window, cx);
977+
self.select_match(Direction::Next, 1, window, cx);
981978
}
982979

983980
fn select_prev_match(
@@ -986,8 +983,7 @@ impl BufferSearchBar {
986983
window: &mut Window,
987984
cx: &mut Context<Self>,
988985
) {
989-
let collapse = vim_flavor(cx) == Some(VimFlavor::Vim);
990-
self.select_match(Direction::Prev, 1, collapse, window, cx);
986+
self.select_match(Direction::Prev, 1, window, cx);
991987
}
992988

993989
pub fn select_all_matches(
@@ -1012,7 +1008,6 @@ impl BufferSearchBar {
10121008
&mut self,
10131009
direction: Direction,
10141010
count: usize,
1015-
collapse: bool,
10161011
window: &mut Window,
10171012
cx: &mut Context<Self>,
10181013
) {
@@ -1035,7 +1030,7 @@ impl BufferSearchBar {
10351030
.match_index_for_direction(matches, index, direction, count, window, cx);
10361031

10371032
searchable_item.update_matches(matches, window, cx);
1038-
searchable_item.activate_match(new_match_index, matches, collapse, window, cx);
1033+
searchable_item.activate_match(new_match_index, matches, window, cx);
10391034
}
10401035
}
10411036

@@ -1049,8 +1044,7 @@ impl BufferSearchBar {
10491044
return;
10501045
}
10511046
searchable_item.update_matches(matches, window, cx);
1052-
let collapse = vim_flavor(cx) == Some(VimFlavor::Vim);
1053-
searchable_item.activate_match(0, matches, collapse, window, cx);
1047+
searchable_item.activate_match(0, matches, window, cx);
10541048
}
10551049
}
10561050

@@ -1065,8 +1059,7 @@ impl BufferSearchBar {
10651059
}
10661060
let new_match_index = matches.len() - 1;
10671061
searchable_item.update_matches(matches, window, cx);
1068-
let collapse = vim_flavor(cx) == Some(VimFlavor::Vim);
1069-
searchable_item.activate_match(new_match_index, matches, collapse, window, cx);
1062+
searchable_item.activate_match(new_match_index, matches, window, cx);
10701063
}
10711064
}
10721065

crates/search/src/project_search.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ use anyhow::Context as _;
99
use collections::HashMap;
1010
use editor::{
1111
Anchor, Editor, EditorEvent, EditorSettings, MAX_TAB_TITLE_LEN, MultiBuffer, PathKey,
12-
SelectionEffects, VimFlavor,
12+
SelectionEffects,
1313
actions::{Backtab, SelectAll, Tab},
1414
items::active_match_index,
1515
multibuffer_context_lines,
1616
scroll::Autoscroll,
17-
vim_flavor,
1817
};
1918
use futures::{StreamExt, stream::FuturesOrdered};
2019
use gpui::{
@@ -1431,8 +1430,7 @@ impl ProjectSearchView {
14311430

14321431
let range_to_select = match_ranges[new_index].clone();
14331432
self.results_editor.update(cx, |editor, cx| {
1434-
let collapse = vim_flavor(cx) == Some(VimFlavor::Vim);
1435-
let range_to_select = editor.range_for_match(&range_to_select, collapse);
1433+
let range_to_select = editor.range_for_match(&range_to_select);
14361434
let autoscroll = if EditorSettings::get_global(cx).search.center_on_match {
14371435
Autoscroll::center()
14381436
} else {
@@ -1509,10 +1507,9 @@ impl ProjectSearchView {
15091507
let is_new_search = self.search_id != prev_search_id;
15101508
self.results_editor.update(cx, |editor, cx| {
15111509
if is_new_search {
1512-
let collapse = vim_flavor(cx) == Some(VimFlavor::Vim);
15131510
let range_to_select = match_ranges
15141511
.first()
1515-
.map(|range| editor.range_for_match(range, collapse));
1512+
.map(|range| editor.range_for_match(range));
15161513
editor.change_selections(Default::default(), window, cx, |s| {
15171514
s.select_ranges(range_to_select)
15181515
});

crates/terminal_view/src/terminal_view.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,6 @@ impl SearchableItem for TerminalView {
14521452
&mut self,
14531453
index: usize,
14541454
_: &[Self::Match],
1455-
_collapse: bool,
14561455
_window: &mut Window,
14571456
cx: &mut Context<Self>,
14581457
) {

crates/vim/src/helix.rs

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ impl Vim {
450450
prior_selections,
451451
prior_operator: self.operator_stack.last().cloned(),
452452
prior_mode: self.mode,
453-
is_helix_regex_search: true,
453+
helix_select: true,
454454
}
455455
});
456456
}
@@ -1278,24 +1278,6 @@ mod test {
12781278
cx.assert_state("«one ˇ»two", Mode::HelixSelect);
12791279
}
12801280

1281-
#[gpui::test]
1282-
async fn test_exit_visual_mode(cx: &mut gpui::TestAppContext) {
1283-
let mut cx = VimTestContext::new(cx, true).await;
1284-
1285-
cx.set_state("ˇone two", Mode::Normal);
1286-
cx.simulate_keystrokes("v w");
1287-
cx.assert_state("«one tˇ»wo", Mode::Visual);
1288-
cx.simulate_keystrokes("escape");
1289-
cx.assert_state("one ˇtwo", Mode::Normal);
1290-
1291-
cx.enable_helix();
1292-
cx.set_state("ˇone two", Mode::HelixNormal);
1293-
cx.simulate_keystrokes("v w");
1294-
cx.assert_state("«one ˇ»two", Mode::HelixSelect);
1295-
cx.simulate_keystrokes("escape");
1296-
cx.assert_state("«one ˇ»two", Mode::HelixNormal);
1297-
}
1298-
12991281
#[gpui::test]
13001282
async fn test_helix_select_regex(cx: &mut gpui::TestAppContext) {
13011283
let mut cx = VimTestContext::new(cx, true).await;
@@ -1315,47 +1297,9 @@ mod test {
13151297
cx.simulate_keystrokes("enter");
13161298
cx.assert_state("«oneˇ» two «oneˇ»", Mode::HelixNormal);
13171299

1318-
// TODO: change "search_in_selection" to not perform any search when in helix select mode with no selection
1319-
// cx.set_state("ˇstuff one two one", Mode::HelixNormal);
1320-
// cx.simulate_keystrokes("s o n e enter");
1321-
// cx.assert_state("ˇstuff one two one", Mode::HelixNormal);
1322-
}
1323-
1324-
#[gpui::test]
1325-
async fn test_helix_select_next_match(cx: &mut gpui::TestAppContext) {
1326-
let mut cx = VimTestContext::new(cx, true).await;
1327-
1328-
cx.set_state("ˇhello two one two one two one", Mode::Visual);
1329-
cx.simulate_keystrokes("/ o n e");
1330-
cx.simulate_keystrokes("enter");
1331-
cx.simulate_keystrokes("n n");
1332-
cx.assert_state("«hello two one two one two oˇ»ne", Mode::Visual);
1333-
1334-
cx.set_state("ˇhello two one two one two one", Mode::Normal);
1335-
cx.simulate_keystrokes("/ o n e");
1336-
cx.simulate_keystrokes("enter");
1337-
cx.simulate_keystrokes("n n");
1338-
cx.assert_state("hello two one two one two ˇone", Mode::Normal);
1339-
1340-
cx.set_state("ˇhello two one two one two one", Mode::Normal);
1341-
cx.simulate_keystrokes("/ o n e");
1342-
cx.simulate_keystrokes("enter");
1343-
cx.simulate_keystrokes("n g n g n");
1344-
cx.assert_state("hello two one two «one two oneˇ»", Mode::Visual);
1345-
1346-
cx.enable_helix();
1347-
1348-
cx.set_state("ˇhello two one two one two one", Mode::HelixNormal);
1349-
cx.simulate_keystrokes("/ o n e");
1350-
cx.simulate_keystrokes("enter");
1351-
cx.simulate_keystrokes("n n");
1352-
cx.assert_state("hello two one two one two «oneˇ»", Mode::HelixNormal);
1353-
1354-
cx.set_state("ˇhello two one two one two one", Mode::HelixSelect);
1355-
cx.simulate_keystrokes("/ o n e");
1356-
cx.simulate_keystrokes("enter");
1357-
cx.simulate_keystrokes("n n");
1358-
cx.assert_state("ˇhello two «oneˇ» two «oneˇ» two «oneˇ»", Mode::HelixSelect);
1300+
cx.set_state("ˇone two one", Mode::HelixNormal);
1301+
cx.simulate_keystrokes("s o n e enter");
1302+
cx.assert_state("ˇone two one", Mode::HelixNormal);
13591303
}
13601304

13611305
#[gpui::test]

0 commit comments

Comments
 (0)