{
use text::ToPoint as _;
@@ -5756,6 +6104,23 @@ impl Editor {
}
match &completion.completion {
+ InlineCompletion::Move {
+ target, snapshot, ..
+ } => Some(
+ h_flex()
+ .px_2()
+ .gap_2()
+ .flex_1()
+ .child(
+ if target.text_anchor.to_point(&snapshot).row > cursor_point.row {
+ Icon::new(IconName::ZedPredictDown)
+ } else {
+ Icon::new(IconName::ZedPredictUp)
+ },
+ )
+ .child(Label::new("Jump to Edit")),
+ ),
+
InlineCompletion::Edit {
edits,
edit_preview,
@@ -5825,103 +6190,11 @@ impl Editor {
.gap_2()
.pr_1()
.overflow_x_hidden()
+ .font(theme::ThemeSettings::get_global(cx).buffer_font.clone())
.child(left)
.child(preview),
)
}
-
- InlineCompletion::Move {
- target,
- range_around_target,
- snapshot,
- } => {
- let highlighted_text = snapshot.highlighted_text_for_range(
- range_around_target.clone(),
- None,
- &style.syntax,
- );
- let base = h_flex().gap_3().flex_1().child(render_relative_row_jump(
- "Jump ",
- cursor_point.row,
- target.text_anchor.to_point(&snapshot).row,
- ));
-
- if highlighted_text.text.is_empty() {
- return Some(base);
- }
-
- let cursor_color = self.current_user_player_color(cx).cursor;
-
- let start_point = range_around_target.start.to_point(&snapshot);
- let end_point = range_around_target.end.to_point(&snapshot);
- let target_point = target.text_anchor.to_point(&snapshot);
-
- let styled_text = highlighted_text.to_styled_text(&style.text);
- let text_len = highlighted_text.text.len();
-
- let cursor_relative_position = window
- .text_system()
- .layout_line(
- highlighted_text.text,
- style.text.font_size.to_pixels(window.rem_size()),
- // We don't need to include highlights
- // because we are only using this for the cursor position
- &[TextRun {
- len: text_len,
- font: style.text.font(),
- color: style.text.color,
- background_color: None,
- underline: None,
- strikethrough: None,
- }],
- )
- .log_err()
- .map(|line| {
- line.x_for_index(
- target_point.column.saturating_sub(start_point.column) as usize
- )
- });
-
- let fade_before = start_point.column > 0;
- let fade_after = end_point.column < snapshot.line_len(end_point.row);
-
- let background = cx.theme().colors().elevated_surface_background;
-
- let preview = h_flex()
- .relative()
- .child(styled_text)
- .when(fade_before, |parent| {
- parent.child(div().absolute().top_0().left_0().w_4().h_full().bg(
- linear_gradient(
- 90.,
- linear_color_stop(background, 0.),
- linear_color_stop(background.opacity(0.), 1.),
- ),
- ))
- })
- .when(fade_after, |parent| {
- parent.child(div().absolute().top_0().right_0().w_4().h_full().bg(
- linear_gradient(
- -90.,
- linear_color_stop(background, 0.),
- linear_color_stop(background.opacity(0.), 1.),
- ),
- ))
- })
- .when_some(cursor_relative_position, |parent, position| {
- parent.child(
- div()
- .w(px(2.))
- .h_full()
- .bg(cursor_color)
- .absolute()
- .top_0()
- .left(position),
- )
- });
-
- Some(base.child(preview))
- }
}
}
@@ -13740,6 +14013,23 @@ impl Editor {
}
}
+ pub fn previewing_edit_prediction_move(
+ &mut self,
+ ) -> Option<(Anchor, &mut EditPredictionPreview)> {
+ if !self.edit_prediction_preview.is_active() {
+ return None;
+ };
+
+ self.active_inline_completion
+ .as_ref()
+ .and_then(|completion| match completion.completion {
+ InlineCompletion::Move { target, .. } => {
+ Some((target, &mut self.edit_prediction_preview))
+ }
+ _ => None,
+ })
+ }
+
pub fn show_local_cursors(&self, window: &mut Window, cx: &mut App) -> bool {
(self.read_only(cx) || self.blink_manager.read(cx).visible())
&& self.focus_handle.is_focused(window)
@@ -14572,7 +14862,7 @@ impl Editor {
}
pub fn has_visible_completions_menu(&self) -> bool {
- !self.previewing_inline_completion
+ !self.edit_prediction_preview.is_active()
&& self.context_menu.borrow().as_ref().map_or(false, |menu| {
menu.visible() && matches!(menu, CodeContextMenu::Completions(_))
})
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index 646822ab46..377a620594 100644
--- a/crates/editor/src/element.rs
+++ b/crates/editor/src/element.rs
@@ -16,12 +16,12 @@ use crate::{
mouse_context_menu::{self, MenuPosition, MouseContextMenu},
scroll::{axis_pair, scroll_amount::ScrollAmount, AxisPair},
AcceptEditPrediction, BlockId, ChunkReplacement, CursorShape, CustomBlockId, DisplayPoint,
- DisplayRow, DocumentHighlightRead, DocumentHighlightWrite, EditDisplayMode, Editor, EditorMode,
- EditorSettings, EditorSnapshot, EditorStyle, ExpandExcerpts, FocusedBlock, GoToHunk,
- GoToPrevHunk, GutterDimensions, HalfPageDown, HalfPageUp, HandleInput, HoveredCursor,
- InlineCompletion, JumpData, LineDown, LineUp, OpenExcerpts, PageDown, PageUp, Point,
- RevertSelectedHunks, RowExt, RowRangeExt, SelectPhase, Selection, SoftWrap,
- StickyHeaderExcerpt, ToPoint, ToggleFold, CURSORS_VISIBLE_FOR,
+ DisplayRow, DocumentHighlightRead, DocumentHighlightWrite, EditDisplayMode,
+ EditPredictionPreview, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle,
+ ExpandExcerpts, FocusedBlock, GoToHunk, GoToPrevHunk, GutterDimensions, HalfPageDown,
+ HalfPageUp, HandleInput, HoveredCursor, InlineCompletion, JumpData, LineDown, LineUp,
+ OpenExcerpts, PageDown, PageUp, Point, RevertSelectedHunks, RowExt, RowRangeExt, SelectPhase,
+ Selection, SoftWrap, StickyHeaderExcerpt, ToPoint, ToggleFold, CURSORS_VISIBLE_FOR,
EDIT_PREDICTION_REQUIRES_MODIFIER_KEY_CONTEXT, FILE_HEADER_HEIGHT,
GIT_BLAME_MAX_AUTHOR_CHARS_DISPLAYED, MAX_LINE_LEN, MULTI_BUFFER_EXCERPT_HEADER_HEIGHT,
};
@@ -1114,18 +1114,44 @@ impl EditorElement {
em_width: Pixels,
em_advance: Pixels,
autoscroll_containing_element: bool,
+ newest_selection_head: Option
,
window: &mut Window,
cx: &mut App,
) -> Vec {
let mut autoscroll_bounds = None;
let cursor_layouts = self.editor.update(cx, |editor, cx| {
let mut cursors = Vec::new();
+
+ let previewing_move =
+ if let Some((target, preview)) = editor.previewing_edit_prediction_move() {
+ cursors.extend(self.layout_edit_prediction_preview_cursor(
+ snapshot,
+ visible_display_row_range.clone(),
+ line_layouts,
+ content_origin,
+ scroll_pixel_position,
+ line_height,
+ em_advance,
+ preview,
+ target,
+ newest_selection_head,
+ window,
+ cx,
+ ));
+
+ true
+ } else {
+ false
+ };
+
+ let show_local_cursors = !previewing_move && editor.show_local_cursors(window, cx);
+
for (player_color, selections) in selections {
for selection in selections {
let cursor_position = selection.head;
let in_range = visible_display_row_range.contains(&cursor_position.row());
- if (selection.is_local && !editor.show_local_cursors(window, cx))
+ if (selection.is_local && !show_local_cursors)
|| !in_range
|| block_start_rows.contains(&cursor_position.row())
{
@@ -1249,6 +1275,7 @@ impl EditorElement {
cursors.push(cursor);
}
}
+
cursors
});
@@ -1259,6 +1286,50 @@ impl EditorElement {
cursor_layouts
}
+ #[allow(clippy::too_many_arguments)]
+ fn layout_edit_prediction_preview_cursor(
+ &self,
+ snapshot: &EditorSnapshot,
+ visible_row_range: Range,
+ line_layouts: &[LineWithInvisibles],
+ content_origin: gpui::Point,
+ scroll_pixel_position: gpui::Point,
+ line_height: Pixels,
+ em_advance: Pixels,
+ preview: &mut EditPredictionPreview,
+ target: Anchor,
+ cursor: Option,
+ window: &mut Window,
+ cx: &mut App,
+ ) -> Option {
+ let state = preview.move_state(
+ snapshot,
+ visible_row_range,
+ line_layouts,
+ scroll_pixel_position,
+ line_height,
+ target,
+ cursor,
+ )?;
+
+ if !state.is_animation_completed() {
+ window.request_animation_frame();
+ }
+
+ let mut cursor = CursorLayout {
+ color: self.style.local_player.cursor,
+ block_width: em_advance,
+ origin: state.position,
+ line_height,
+ shape: CursorShape::Bar,
+ block_text: None,
+ cursor_name: None,
+ };
+
+ cursor.layout(content_origin, None, window, cx);
+ Some(cursor)
+ }
+
fn layout_scrollbars(
&self,
snapshot: &EditorSnapshot,
@@ -3531,7 +3602,7 @@ impl EditorElement {
}
#[allow(clippy::too_many_arguments)]
- fn layout_inline_completion_popover(
+ fn layout_edit_prediction_popover(
&self,
text_bounds: &Bounds,
editor_snapshot: &EditorSnapshot,
@@ -3559,6 +3630,49 @@ impl EditorElement {
match &active_inline_completion.completion {
InlineCompletion::Move { target, .. } => {
+ if editor.edit_prediction_requires_modifier() {
+ let cursor_position =
+ target.to_display_point(&editor_snapshot.display_snapshot);
+
+ if !editor.edit_prediction_preview.is_active_settled()
+ || !visible_row_range.contains(&cursor_position.row())
+ {
+ return None;
+ }
+
+ let accept_keybind = editor.accept_edit_prediction_keybind(window, cx);
+ let accept_keystroke = accept_keybind.keystroke()?;
+
+ let mut element = div()
+ .px_2()
+ .py_1()
+ .elevation_2(cx)
+ .border_color(cx.theme().colors().border)
+ .rounded_br(px(0.))
+ .child(Label::new(accept_keystroke.key.clone()).buffer_font(cx))
+ .into_any();
+
+ let size = element.layout_as_root(AvailableSpace::min_size(), window, cx);
+
+ let cursor_row_layout = &line_layouts
+ [cursor_position.row().minus(visible_row_range.start) as usize];
+ let cursor_column = cursor_position.column() as usize;
+
+ let cursor_character_x = cursor_row_layout.x_for_index(cursor_column);
+ let target_y = (cursor_position.row().as_f32()
+ - scroll_pixel_position.y / line_height)
+ * line_height;
+
+ let offset = point(
+ cursor_character_x - size.width,
+ target_y - size.height - PADDING_Y,
+ );
+
+ element.prepaint_at(text_bounds.origin + offset, window, cx);
+
+ return Some(element);
+ }
+
let target_display_point = target.to_display_point(editor_snapshot);
if target_display_point.row().as_f32() < scroll_top {
let mut element = inline_completion_accept_indicator(
@@ -5688,7 +5802,7 @@ fn inline_completion_accept_indicator(
.text_size(TextSize::XSmall.rems(cx))
.text_color(cx.theme().colors().text)
.gap_1()
- .when(!editor.previewing_inline_completion, |parent| {
+ .when(!editor.edit_prediction_preview.is_active(), |parent| {
parent.children(ui::render_modifiers(
&accept_keystroke.modifiers,
PlatformStyle::platform(),
@@ -7246,6 +7360,7 @@ impl Element for EditorElement {
em_width,
em_advance,
autoscroll_containing_element,
+ newest_selection_head,
window,
cx,
);
@@ -7397,7 +7512,7 @@ impl Element for EditorElement {
);
}
- let inline_completion_popover = self.layout_inline_completion_popover(
+ let inline_completion_popover = self.layout_edit_prediction_popover(
&text_hitbox.bounds,
&snapshot,
start_row..end_row,
diff --git a/crates/editor/src/scroll/autoscroll.rs b/crates/editor/src/scroll/autoscroll.rs
index 7b6a9fc962..d4c57fd113 100644
--- a/crates/editor/src/scroll/autoscroll.rs
+++ b/crates/editor/src/scroll/autoscroll.rs
@@ -113,6 +113,7 @@ impl Editor {
target_bottom = target_top + 1.;
} else {
let selections = self.selections.all::(cx);
+
target_top = selections
.first()
.unwrap()
@@ -144,6 +145,29 @@ impl Editor {
target_top = newest_selection_top;
target_bottom = newest_selection_top + 1.;
}
+
+ if self.edit_prediction_preview.is_active() {
+ if let Some(completion) = self.active_inline_completion.as_ref() {
+ match completion.completion {
+ crate::InlineCompletion::Edit { .. } => {}
+ crate::InlineCompletion::Move { target, .. } => {
+ let target_row = target.to_display_point(&display_map).row().as_f32();
+
+ if target_row < target_top {
+ target_top = target_row;
+ } else if target_row >= target_bottom {
+ target_bottom = target_row + 1.;
+ }
+
+ let selections_fit = target_bottom - target_top <= visible_lines;
+ if !selections_fit {
+ target_top = target_row;
+ target_bottom = target_row + 1.;
+ }
+ }
+ }
+ }
+ }
}
let margin = if matches!(self.mode, EditorMode::AutoHeight { .. }) {
diff --git a/crates/ui/src/components/icon.rs b/crates/ui/src/components/icon.rs
index 40d1a422dd..d8043f7400 100644
--- a/crates/ui/src/components/icon.rs
+++ b/crates/ui/src/components/icon.rs
@@ -324,6 +324,8 @@ pub enum IconName {
ZedAssistant2,
ZedAssistantFilled,
ZedPredict,
+ ZedPredictUp,
+ ZedPredictDown,
ZedPredictDisabled,
ZedXCopilot,
}