From 556b0eb4f16b3e1b2335ce5a0315e3516946386e Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Tue, 4 Feb 2025 01:00:48 -0700 Subject: [PATCH] Show larger jump target preview + add ellipsii to indicate truncation (#24179) Release Notes: - N/A --- crates/editor/src/editor.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index c4760cae91f4bc557e66e42c8f50b6bd3b3c9f0b..aa01d8002436971d7c6d6417246c64ef10e4fbe3 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5073,15 +5073,13 @@ impl Editor { let target_point = text::ToPoint::to_point(&target.text_anchor, &snapshot); // TODO: Base this off of TreeSitter or word boundaries? let target_excerpt_begin = snapshot.anchor_before(snapshot.clip_point( - Point::new(target_point.row, target_point.column.saturating_sub(10)), + Point::new(target_point.row, target_point.column.saturating_sub(20)), Bias::Left, )); let target_excerpt_end = snapshot.anchor_after(snapshot.clip_point( - Point::new(target_point.row, target_point.column + 10), + Point::new(target_point.row, target_point.column + 20), Bias::Right, )); - // TODO: Extend this to be before the jump target, and draw a cursor at the jump target - // (using Editor::current_user_player_color). let range_around_target = target_excerpt_begin..target_excerpt_end; InlineCompletion::Move { target, @@ -5656,14 +5654,14 @@ impl Editor { &style.syntax, ); let cursor_color = self.current_user_player_color(cx).cursor; - let target_offset = + let target_ix = text::ToOffset::to_offset(&target.text_anchor, &snapshot).saturating_sub( text::ToOffset::to_offset(&range_around_target.start, &snapshot), ); highlighted_text.highlights = gpui::combine_highlights( highlighted_text.highlights, iter::once(( - target_offset..target_offset + 1, + target_ix..target_ix + 1, HighlightStyle { background_color: Some(cursor_color), ..Default::default() @@ -5672,6 +5670,11 @@ impl Editor { ) .collect::>(); + let start_point = range_around_target.start.to_point(&snapshot); + let end_point = range_around_target.end.to_point(&snapshot); + let ellipsis_before = start_point.column > 0; + let ellipsis_after = end_point.column < snapshot.line_len(end_point.row); + Some( h_flex() .gap_3() @@ -5681,7 +5684,12 @@ impl Editor { target.text_anchor.to_point(&snapshot).row, )) .when(!highlighted_text.text.is_empty(), |parent| { - parent.child(highlighted_text.to_styled_text(&style.text)) + parent.child( + h_flex() + .when(ellipsis_before, |parent| parent.child("…")) + .child(highlighted_text.to_styled_text(&style.text)) + .when(ellipsis_after, |parent| parent.child("…")), + ) }), ) }