Improve the clarity of multi buffer headers (#9722)

<img width="544" alt="Screenshot 2024-03-22 at 3 23 09 PM"
src="https://github.com/zed-industries/zed/assets/2280405/83fde9ad-76e1-4eed-a3f2-bc25d5a88d84">

Release Notes:


- Improved the clarity of the UI for diagnostic and search result
headers
This commit is contained in:
Mikayla Maki 2024-03-22 15:38:19 -07:00 committed by GitHub
parent 16a2013021
commit 4459eacc98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,7 +20,7 @@ use anyhow::Result;
use collections::{BTreeMap, HashMap}; use collections::{BTreeMap, HashMap};
use git::diff::DiffHunkStatus; use git::diff::DiffHunkStatus;
use gpui::{ use gpui::{
div, fill, outline, overlay, point, px, quad, relative, size, transparent_black, Action, div, fill, outline, overlay, point, px, quad, relative, size, svg, transparent_black, Action,
AnchorCorner, AnyElement, AvailableSpace, Bounds, ContentMask, Corners, CursorStyle, AnchorCorner, AnyElement, AvailableSpace, Bounds, ContentMask, Corners, CursorStyle,
DispatchPhase, Edges, Element, ElementContext, ElementInputHandler, Entity, Hitbox, Hsla, DispatchPhase, Edges, Element, ElementContext, ElementInputHandler, Entity, Hitbox, Hsla,
InteractiveElement, IntoElement, ModifiersChangedEvent, MouseButton, MouseDownEvent, InteractiveElement, IntoElement, ModifiersChangedEvent, MouseButton, MouseDownEvent,
@ -1390,7 +1390,14 @@ impl EditorElement {
.map(|project| project.read(cx).visible_worktrees(cx).count() > 1) .map(|project| project.read(cx).visible_worktrees(cx).count() > 1)
.unwrap_or_default(); .unwrap_or_default();
let jump_handler = project::File::from_dyn(buffer.file()).map(|file| { #[derive(Clone)]
struct JumpData {
position: Point,
anchor: text::Anchor,
path: ProjectPath,
}
let jump_data = project::File::from_dyn(buffer.file()).map(|file| {
let jump_path = ProjectPath { let jump_path = ProjectPath {
worktree_id: file.worktree_id(cx), worktree_id: file.worktree_id(cx),
path: file.path.clone(), path: file.path.clone(),
@ -1401,9 +1408,11 @@ impl EditorElement {
.map_or(range.context.start, |primary| primary.start); .map_or(range.context.start, |primary| primary.start);
let jump_position = language::ToPoint::to_point(&jump_anchor, buffer); let jump_position = language::ToPoint::to_point(&jump_anchor, buffer);
cx.listener_for(&self.editor, move |editor, _, cx| { JumpData {
editor.jump(jump_path.clone(), jump_position, jump_anchor, cx); position: jump_position,
}) anchor: jump_anchor,
path: jump_path,
}
}); });
let element = if *starts_new_buffer { let element = if *starts_new_buffer {
@ -1454,11 +1463,11 @@ impl EditorElement {
}), }),
), ),
) )
.when_some(jump_handler, |this, jump_handler| { .when_some(jump_data.clone(), |this, jump_data| {
this.cursor_pointer() this.cursor_pointer()
.tooltip(|cx| { .tooltip(|cx| {
Tooltip::for_action( Tooltip::for_action(
"Jump to Buffer", "Jump to File",
&OpenExcerpts, &OpenExcerpts,
cx, cx,
) )
@ -1466,30 +1475,32 @@ impl EditorElement {
.on_mouse_down(MouseButton::Left, |_, cx| { .on_mouse_down(MouseButton::Left, |_, cx| {
cx.stop_propagation() cx.stop_propagation()
}) })
.on_click(jump_handler) .on_click(cx.listener_for(&self.editor, {
move |editor, _, cx| {
editor.jump(
jump_data.path.clone(),
jump_data.position,
jump_data.anchor,
cx,
);
}
}))
}), }),
) )
} else { } else {
h_flex() v_flex()
.id(("collapsed context", block_id)) .id(("collapsed context", block_id))
.size_full() .size_full()
.gap(gutter_dimensions.left_padding + gutter_dimensions.right_padding)
.child( .child(
h_flex() div()
.justify_end() .flex()
.flex_none() .v_flex()
.w(gutter_dimensions.width .justify_start()
- (gutter_dimensions.left_padding .id("jump to collapsed context")
+ gutter_dimensions.right_padding)) .group("")
.w(relative(1.0))
.h_full() .h_full()
.text_buffer(cx) .cursor_pointer()
.text_color(cx.theme().colors().editor_line_number)
.child("..."),
)
.child(
ButtonLike::new("jump to collapsed context")
.style(ButtonStyle::Transparent)
.full_width()
.child( .child(
div() div()
.h_px() .h_px()
@ -1499,12 +1510,85 @@ impl EditorElement {
style.bg(cx.theme().colors().border) style.bg(cx.theme().colors().border)
}), }),
) )
.when_some(jump_handler, |this, jump_handler| { .when_some(jump_data.clone(), |this, jump_data| {
this.on_click(jump_handler).tooltip(|cx| { this.on_click(cx.listener_for(&self.editor, {
Tooltip::for_action("Jump to Buffer", &OpenExcerpts, cx) let path = jump_data.path.clone();
}) move |editor, _, cx| {
cx.stop_propagation();
editor.jump(
path.clone(),
jump_data.position,
jump_data.anchor,
cx,
);
}
}))
.tooltip(
move |cx| {
Tooltip::for_action(
format!(
"Jump to {}:L{}",
jump_data.path.path.display(),
jump_data.position.row + 1
),
&OpenExcerpts,
cx,
)
},
)
}), }),
) )
.child(
h_flex()
.justify_end()
.flex_none()
.w(
gutter_dimensions.width - (gutter_dimensions.left_padding), // + gutter_dimensions.right_padding)
)
.h_full()
.child(
ButtonLike::new("jump-icon")
.style(ButtonStyle::Transparent)
.child(
svg()
.path(IconName::ArrowUpRight.path())
.size(IconSize::XSmall.rems())
.text_color(cx.theme().colors().border)
.group_hover("", |style| {
style.text_color(
cx.theme().colors().editor_line_number,
)
}),
)
.when_some(jump_data.clone(), |this, jump_data| {
this.on_click(cx.listener_for(&self.editor, {
let path = jump_data.path.clone();
move |editor, _, cx| {
editor.jump(
path.clone(),
jump_data.position,
jump_data.anchor,
cx,
);
}
}))
.tooltip({
move |cx| {
Tooltip::for_action(
format!(
"Jump to {}:L{}",
jump_data.path.path.display(),
jump_data.position.row + 1
),
&OpenExcerpts,
cx,
)
}
})
}),
),
)
}; };
element.into_any() element.into_any()
} }