diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 5efc578eff4b8ce9ba7b0e7731b2109dbb2339f9..2d98f8c3f9dcd7237242b3e342747caba0b18965 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -8365,7 +8365,25 @@ impl Editor { let range = target.range.to_offset(target.buffer.read(cx)); let range = editor.range_for_match(&range); + + /// If select range has more than one line, we + /// just point the cursor to range.start. + fn check_multiline_range( + buffer: &Buffer, + range: Range, + ) -> Range { + if buffer.offset_to_point(range.start).row + == buffer.offset_to_point(range.end).row + { + range + } else { + range.start..range.start + } + } + if Some(&target.buffer) == editor.buffer.read(cx).as_singleton().as_ref() { + let buffer = target.buffer.read(cx); + let range = check_multiline_range(buffer, range); editor.change_selections(Some(Autoscroll::focused()), cx, |s| { s.select_ranges([range]); }); @@ -8385,6 +8403,8 @@ impl Editor { // When selecting a definition in a different buffer, disable the nav history // to avoid creating a history entry at the previous cursor location. pane.update(cx, |pane, _| pane.disable_history()); + let buffer = target.buffer.read(cx); + let range = check_multiline_range(buffer, range); target_editor.change_selections( Some(Autoscroll::focused()), cx,