Rework context insertion UX (#12360)
- Confirming a completion now runs the command immediately - Hitting `enter` on a line with a command now runs it - The output of commands gets folded away and replaced with a custom placeholder - Eliminated ambient context <img width="1588" alt="image" src="https://github.com/zed-industries/zed/assets/482957/b1927a45-52d6-4634-acc9-2ee539c1d89a"> Release Notes: - N/A --------- Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
co-authored by
Nathan Sobo
parent
20f37f0647
commit
7e3ab9acc9
@@ -36,7 +36,13 @@ impl FlapSnapshot {
|
||||
while let Some(item) = cursor.item() {
|
||||
match Ord::cmp(&item.flap.range.start.to_point(snapshot).row, &row.0) {
|
||||
Ordering::Less => cursor.next(snapshot),
|
||||
Ordering::Equal => return Some(&item.flap),
|
||||
Ordering::Equal => {
|
||||
if item.flap.range.start.is_valid(snapshot) {
|
||||
return Some(&item.flap);
|
||||
} else {
|
||||
cursor.next(snapshot);
|
||||
}
|
||||
}
|
||||
Ordering::Greater => break,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ pub struct FoldPlaceholder {
|
||||
pub render: Arc<dyn Send + Sync + Fn(FoldId, Range<Anchor>, &mut WindowContext) -> AnyElement>,
|
||||
/// If true, the element is constrained to the shaped width of an ellipsis.
|
||||
pub constrain_width: bool,
|
||||
/// If true, merges the fold with an adjacent one.
|
||||
pub merge_adjacent: bool,
|
||||
}
|
||||
|
||||
impl FoldPlaceholder {
|
||||
@@ -30,6 +32,7 @@ impl FoldPlaceholder {
|
||||
Self {
|
||||
render: Arc::new(|_id, _range, _cx| gpui::Empty.into_any_element()),
|
||||
constrain_width: true,
|
||||
merge_adjacent: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -374,8 +377,11 @@ impl FoldMap {
|
||||
|
||||
assert!(fold_range.start.0 >= sum.input.len);
|
||||
|
||||
while folds.peek().map_or(false, |(_, next_fold_range)| {
|
||||
next_fold_range.start <= fold_range.end
|
||||
while folds.peek().map_or(false, |(next_fold, next_fold_range)| {
|
||||
next_fold_range.start < fold_range.end
|
||||
|| (next_fold_range.start == fold_range.end
|
||||
&& fold.placeholder.merge_adjacent
|
||||
&& next_fold.placeholder.merge_adjacent)
|
||||
}) {
|
||||
let (_, next_fold_range) = folds.next().unwrap();
|
||||
if next_fold_range.end > fold_range.end {
|
||||
|
||||
@@ -1628,6 +1628,7 @@ impl Editor {
|
||||
})
|
||||
.into_any()
|
||||
}),
|
||||
merge_adjacent: true,
|
||||
};
|
||||
let display_map = cx.new_model(|cx| {
|
||||
let file_header_size = if show_excerpt_controls { 3 } else { 2 };
|
||||
@@ -3905,6 +3906,7 @@ impl Editor {
|
||||
|
||||
let snippet;
|
||||
let text;
|
||||
|
||||
if completion.is_snippet() {
|
||||
snippet = Some(Snippet::parse(&completion.new_text).log_err()?);
|
||||
text = snippet.as_ref().unwrap().text.clone();
|
||||
@@ -3998,6 +4000,10 @@ impl Editor {
|
||||
this.refresh_inline_completion(true, cx);
|
||||
});
|
||||
|
||||
if let Some(confirm) = completion.confirm.as_ref() {
|
||||
(confirm)(cx);
|
||||
}
|
||||
|
||||
let provider = self.completion_provider.as_ref()?;
|
||||
let apply_edits = provider.apply_additional_edits_for_completion(
|
||||
buffer_handle,
|
||||
|
||||
@@ -3908,7 +3908,7 @@ enum LineFragment {
|
||||
Text(ShapedLine),
|
||||
Element {
|
||||
element: Option<AnyElement>,
|
||||
width: Pixels,
|
||||
size: Size<Pixels>,
|
||||
len: usize,
|
||||
},
|
||||
}
|
||||
@@ -3917,9 +3917,9 @@ impl fmt::Debug for LineFragment {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
LineFragment::Text(shaped_line) => f.debug_tuple("Text").field(shaped_line).finish(),
|
||||
LineFragment::Element { width, len, .. } => f
|
||||
LineFragment::Element { size, len, .. } => f
|
||||
.debug_struct("Element")
|
||||
.field("width", width)
|
||||
.field("size", size)
|
||||
.field("len", len)
|
||||
.finish(),
|
||||
}
|
||||
@@ -3999,7 +3999,7 @@ impl LineWithInvisibles {
|
||||
len += highlighted_chunk.text.len();
|
||||
fragments.push(LineFragment::Element {
|
||||
element: Some(element),
|
||||
width: size.width,
|
||||
size,
|
||||
len: highlighted_chunk.text.len(),
|
||||
});
|
||||
} else {
|
||||
@@ -4112,13 +4112,18 @@ impl LineWithInvisibles {
|
||||
LineFragment::Text(line) => {
|
||||
fragment_origin.x += line.width;
|
||||
}
|
||||
LineFragment::Element { element, width, .. } => {
|
||||
LineFragment::Element { element, size, .. } => {
|
||||
let mut element = element
|
||||
.take()
|
||||
.expect("you can't prepaint LineWithInvisibles twice");
|
||||
element.prepaint_at(fragment_origin, cx);
|
||||
|
||||
// Center the element vertically within the line.
|
||||
let mut element_origin = fragment_origin;
|
||||
element_origin.y += (line_height - size.height) / 2.;
|
||||
element.prepaint_at(element_origin, cx);
|
||||
line_elements.push(element);
|
||||
fragment_origin.x += *width;
|
||||
|
||||
fragment_origin.x += size.width;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4146,8 +4151,8 @@ impl LineWithInvisibles {
|
||||
line.paint(fragment_origin, line_height, cx).log_err();
|
||||
fragment_origin.x += line.width;
|
||||
}
|
||||
LineFragment::Element { width, .. } => {
|
||||
fragment_origin.x += *width;
|
||||
LineFragment::Element { size, .. } => {
|
||||
fragment_origin.x += size.width;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4225,12 +4230,12 @@ impl LineWithInvisibles {
|
||||
fragment_start_x += shaped_line.width;
|
||||
fragment_start_index = fragment_end_index;
|
||||
}
|
||||
LineFragment::Element { len, width, .. } => {
|
||||
LineFragment::Element { len, size, .. } => {
|
||||
let fragment_end_index = fragment_start_index + len;
|
||||
if index < fragment_end_index {
|
||||
return fragment_start_x;
|
||||
}
|
||||
fragment_start_x += *width;
|
||||
fragment_start_x += size.width;
|
||||
fragment_start_index = fragment_end_index;
|
||||
}
|
||||
}
|
||||
@@ -4255,8 +4260,8 @@ impl LineWithInvisibles {
|
||||
fragment_start_x = fragment_end_x;
|
||||
fragment_start_index += shaped_line.len;
|
||||
}
|
||||
LineFragment::Element { len, width, .. } => {
|
||||
let fragment_end_x = fragment_start_x + *width;
|
||||
LineFragment::Element { len, size, .. } => {
|
||||
let fragment_end_x = fragment_start_x + size.width;
|
||||
if x < fragment_end_x {
|
||||
return Some(fragment_start_index);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user