mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-20 02:47:34 +03:00
Move multibuffer "go to file" button into the buffer header (#3777)
Release Notes: - N/A
This commit is contained in:
commit
e3eafdba59
@ -493,8 +493,8 @@ impl EditorElement {
|
||||
event: &MouseMoveEvent,
|
||||
position_map: &PositionMap,
|
||||
text_bounds: Bounds<Pixels>,
|
||||
gutter_bounds: Bounds<Pixels>,
|
||||
stacking_order: &StackingOrder,
|
||||
_gutter_bounds: Bounds<Pixels>,
|
||||
_stacking_order: &StackingOrder,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) {
|
||||
if !editor.has_pending_selection() {
|
||||
@ -738,7 +738,7 @@ impl EditorElement {
|
||||
|
||||
cx.with_z_index(1, |cx| {
|
||||
for (ix, fold_indicator) in layout.fold_indicators.drain(..).enumerate() {
|
||||
if let Some(mut fold_indicator) = fold_indicator {
|
||||
if let Some(fold_indicator) = fold_indicator {
|
||||
let mut fold_indicator = fold_indicator.into_any_element();
|
||||
let available_space = size(
|
||||
AvailableSpace::MinContent,
|
||||
@ -867,7 +867,6 @@ impl EditorElement {
|
||||
layout: &mut LayoutState,
|
||||
cx: &mut WindowContext,
|
||||
) {
|
||||
let scroll_position = layout.position_map.snapshot.scroll_position();
|
||||
let start_row = layout.visible_display_row_range.start;
|
||||
let content_origin = text_bounds.origin + point(layout.gutter_margin, Pixels::ZERO);
|
||||
let line_end_overshoot = 0.15 * layout.position_map.line_height;
|
||||
@ -1411,7 +1410,7 @@ impl EditorElement {
|
||||
if self.editor.read(cx).scroll_manager.is_dragging_scrollbar() {
|
||||
cx.on_mouse_event({
|
||||
let editor = self.editor.clone();
|
||||
move |event: &MouseUpEvent, phase, cx| {
|
||||
move |_: &MouseUpEvent, phase, cx| {
|
||||
if phase == DispatchPhase::Capture {
|
||||
return;
|
||||
}
|
||||
@ -1767,11 +1766,7 @@ impl EditorElement {
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_layout(
|
||||
&mut self,
|
||||
mut bounds: Bounds<Pixels>,
|
||||
cx: &mut WindowContext,
|
||||
) -> LayoutState {
|
||||
fn compute_layout(&mut self, bounds: Bounds<Pixels>, cx: &mut WindowContext) -> LayoutState {
|
||||
self.editor.update(cx, |editor, cx| {
|
||||
let snapshot = editor.snapshot(cx);
|
||||
let style = self.style.clone();
|
||||
@ -1811,7 +1806,7 @@ impl EditorElement {
|
||||
|
||||
let text_width = bounds.size.width - gutter_width;
|
||||
let overscroll = size(em_width, px(0.));
|
||||
let snapshot = {
|
||||
let _snapshot = {
|
||||
editor.set_visible_line_count((bounds.size.height / line_height).into(), cx);
|
||||
|
||||
let editor_width = text_width - gutter_margin - overscroll.width - em_width;
|
||||
@ -1834,7 +1829,6 @@ impl EditorElement {
|
||||
.map(|(guide, active)| (self.column_pixels(*guide, cx), *active))
|
||||
.collect::<SmallVec<[_; 2]>>();
|
||||
|
||||
let scroll_height = Pixels::from(snapshot.max_point().row() + 1) * line_height;
|
||||
let gutter_size = size(gutter_width, bounds.size.height);
|
||||
let text_size = size(text_width, bounds.size.height);
|
||||
|
||||
@ -2101,7 +2095,7 @@ impl EditorElement {
|
||||
.max(MIN_POPOVER_LINE_HEIGHT * line_height), // Apply minimum height of 4 lines
|
||||
);
|
||||
|
||||
let mut hover = editor.hover_state.render(
|
||||
let hover = editor.hover_state.render(
|
||||
&snapshot,
|
||||
&style,
|
||||
visible_rows,
|
||||
@ -2110,7 +2104,7 @@ impl EditorElement {
|
||||
cx,
|
||||
);
|
||||
|
||||
let mut fold_indicators = cx.with_element_id(Some("gutter_fold_indicators"), |cx| {
|
||||
let fold_indicators = cx.with_element_id(Some("gutter_fold_indicators"), |cx| {
|
||||
editor.render_fold_indicators(
|
||||
fold_statuses,
|
||||
&style,
|
||||
@ -2212,7 +2206,6 @@ impl EditorElement {
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) -> (Pixels, Vec<BlockLayout>) {
|
||||
let mut block_id = 0;
|
||||
let scroll_x = snapshot.scroll_anchor.offset.x;
|
||||
let (fixed_blocks, non_fixed_blocks) = snapshot
|
||||
.blocks_in_range(rows.clone())
|
||||
.partition::<Vec<_>, _>(|(_, block)| match block {
|
||||
@ -2220,11 +2213,11 @@ impl EditorElement {
|
||||
TransformBlock::Custom(block) => block.style() == BlockStyle::Fixed,
|
||||
});
|
||||
|
||||
let mut render_block = |block: &TransformBlock,
|
||||
available_space: Size<AvailableSpace>,
|
||||
block_id: usize,
|
||||
editor: &mut Editor,
|
||||
cx: &mut ViewContext<Editor>| {
|
||||
let render_block = |block: &TransformBlock,
|
||||
available_space: Size<AvailableSpace>,
|
||||
block_id: usize,
|
||||
editor: &mut Editor,
|
||||
cx: &mut ViewContext<Editor>| {
|
||||
let mut element = match block {
|
||||
TransformBlock::Custom(block) => {
|
||||
let align_to = block
|
||||
@ -2277,7 +2270,7 @@ impl EditorElement {
|
||||
.map_or(range.context.start, |primary| primary.start);
|
||||
let jump_position = language::ToPoint::to_point(&jump_anchor, buffer);
|
||||
|
||||
let jump_handler = cx.listener_for(&self.editor, move |editor, e, cx| {
|
||||
let jump_handler = cx.listener_for(&self.editor, move |editor, _, cx| {
|
||||
editor.jump(jump_path.clone(), jump_position, jump_anchor, cx);
|
||||
});
|
||||
|
||||
@ -2296,49 +2289,55 @@ impl EditorElement {
|
||||
.map(|p| SharedString::from(p.to_string_lossy().to_string() + "/"));
|
||||
}
|
||||
|
||||
let is_open = true;
|
||||
|
||||
div().id("path header container").size_full().p_1p5().child(
|
||||
h_stack()
|
||||
.id("path header block")
|
||||
.py_1p5()
|
||||
.pl_3()
|
||||
.pr_2()
|
||||
.rounded_lg()
|
||||
.shadow_md()
|
||||
.border()
|
||||
.border_color(cx.theme().colors().border)
|
||||
.bg(cx.theme().colors().editor_subheader_background)
|
||||
.justify_between()
|
||||
.cursor_pointer()
|
||||
.hover(|style| style.bg(cx.theme().colors().element_hover))
|
||||
.child(
|
||||
h_stack().gap_3().child(
|
||||
h_stack()
|
||||
.gap_2()
|
||||
.child(Label::new(
|
||||
filename
|
||||
.map(SharedString::from)
|
||||
.unwrap_or_else(|| "untitled".into()),
|
||||
))
|
||||
.when_some(parent_path, |then, path| {
|
||||
then.child(Label::new(path).color(Color::Muted))
|
||||
}),
|
||||
),
|
||||
)
|
||||
.children(jump_handler.map(|jump_handler| {
|
||||
IconButton::new(block_id, Icon::ArrowUpRight)
|
||||
.style(ButtonStyle::Subtle)
|
||||
.on_click(jump_handler)
|
||||
.tooltip(|cx| {
|
||||
Tooltip::for_action("Jump to Buffer", &OpenExcerpts, cx)
|
||||
})
|
||||
})), // .p_x(gutter_padding)
|
||||
)
|
||||
div()
|
||||
.id(("path header container", block_id))
|
||||
.size_full()
|
||||
.p_1p5()
|
||||
.child(
|
||||
h_stack()
|
||||
.id("path header block")
|
||||
.py_1p5()
|
||||
.pl_3()
|
||||
.pr_2()
|
||||
.rounded_lg()
|
||||
.shadow_md()
|
||||
.border()
|
||||
.border_color(cx.theme().colors().border)
|
||||
.bg(cx.theme().colors().editor_subheader_background)
|
||||
.justify_between()
|
||||
.hover(|style| style.bg(cx.theme().colors().element_hover))
|
||||
.child(
|
||||
h_stack().gap_3().child(
|
||||
h_stack()
|
||||
.gap_2()
|
||||
.child(Label::new(
|
||||
filename
|
||||
.map(SharedString::from)
|
||||
.unwrap_or_else(|| "untitled".into()),
|
||||
))
|
||||
.when_some(parent_path, |then, path| {
|
||||
then.child(Label::new(path).color(Color::Muted))
|
||||
}),
|
||||
),
|
||||
)
|
||||
.when_some(jump_handler, |this, jump_handler| {
|
||||
this.cursor_pointer()
|
||||
.tooltip(|cx| {
|
||||
Tooltip::for_action(
|
||||
"Jump to Buffer",
|
||||
&OpenExcerpts,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.on_mouse_down(MouseButton::Left, |_, cx| {
|
||||
cx.stop_propagation()
|
||||
})
|
||||
.on_click(jump_handler)
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
let text_style = style.text.clone();
|
||||
h_stack()
|
||||
.id("collapsed context")
|
||||
.id(("collapsed context", block_id))
|
||||
.size_full()
|
||||
.gap(gutter_padding)
|
||||
.child(
|
||||
@ -2447,7 +2446,6 @@ impl EditorElement {
|
||||
layout: &LayoutState,
|
||||
cx: &mut WindowContext,
|
||||
) {
|
||||
let content_origin = text_bounds.origin + point(layout.gutter_margin, Pixels::ZERO);
|
||||
let interactive_bounds = InteractiveBounds {
|
||||
bounds: bounds.intersect(&cx.content_mask().bounds),
|
||||
stacking_order: cx.stacking_order().clone(),
|
||||
@ -2764,7 +2762,7 @@ impl Element for EditorElement {
|
||||
|
||||
fn layout(
|
||||
&mut self,
|
||||
element_state: Option<Self::State>,
|
||||
_element_state: Option<Self::State>,
|
||||
cx: &mut gpui::WindowContext,
|
||||
) -> (gpui::LayoutId, Self::State) {
|
||||
self.editor.update(cx, |editor, cx| {
|
||||
@ -2782,22 +2780,19 @@ impl Element for EditorElement {
|
||||
let editor_handle = cx.view().clone();
|
||||
let max_line_number_width =
|
||||
self.max_line_number_width(&editor.snapshot(cx), cx);
|
||||
cx.request_measured_layout(
|
||||
Style::default(),
|
||||
move |known_dimensions, available_space, cx| {
|
||||
editor_handle
|
||||
.update(cx, |editor, cx| {
|
||||
compute_auto_height_layout(
|
||||
editor,
|
||||
max_lines,
|
||||
max_line_number_width,
|
||||
known_dimensions,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.unwrap_or_default()
|
||||
},
|
||||
)
|
||||
cx.request_measured_layout(Style::default(), move |known_dimensions, _, cx| {
|
||||
editor_handle
|
||||
.update(cx, |editor, cx| {
|
||||
compute_auto_height_layout(
|
||||
editor,
|
||||
max_lines,
|
||||
max_line_number_width,
|
||||
known_dimensions,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.unwrap_or_default()
|
||||
})
|
||||
}
|
||||
EditorMode::Full => {
|
||||
let mut style = Style::default();
|
||||
@ -2814,7 +2809,7 @@ impl Element for EditorElement {
|
||||
fn paint(
|
||||
&mut self,
|
||||
bounds: Bounds<gpui::Pixels>,
|
||||
element_state: &mut Self::State,
|
||||
_element_state: &mut Self::State,
|
||||
cx: &mut gpui::WindowContext,
|
||||
) {
|
||||
let editor = self.editor.clone();
|
||||
@ -2847,17 +2842,19 @@ impl Element for EditorElement {
|
||||
|
||||
cx.with_z_index(0, |cx| {
|
||||
self.paint_mouse_listeners(bounds, gutter_bounds, text_bounds, &layout, cx);
|
||||
|
||||
if !layout.blocks.is_empty() {
|
||||
cx.with_element_id(Some("editor_blocks"), |cx| {
|
||||
self.paint_blocks(bounds, &mut layout, cx);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
cx.with_z_index(1, |cx| self.paint_scrollbar(bounds, &mut layout, cx));
|
||||
|
||||
cx.with_z_index(2, |cx| {
|
||||
if !layout.blocks.is_empty() {
|
||||
cx.with_z_index(2, |cx| {
|
||||
cx.with_element_id(Some("editor_blocks"), |cx| {
|
||||
self.paint_blocks(bounds, &mut layout, cx);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
cx.with_z_index(3, |cx| {
|
||||
self.paint_overlays(text_bounds, &mut layout, cx);
|
||||
});
|
||||
});
|
||||
@ -3137,7 +3134,7 @@ impl HighlightedRange {
|
||||
&self,
|
||||
start_y: Pixels,
|
||||
lines: &[HighlightedRangeLine],
|
||||
bounds: Bounds<Pixels>,
|
||||
_bounds: Bounds<Pixels>,
|
||||
cx: &mut WindowContext,
|
||||
) {
|
||||
if lines.is_empty() {
|
||||
@ -3755,7 +3752,7 @@ fn compute_auto_height_layout(
|
||||
known_dimensions: Size<Option<Pixels>>,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) -> Option<Size<Pixels>> {
|
||||
let mut width = known_dimensions.width?;
|
||||
let width = known_dimensions.width?;
|
||||
if let Some(height) = known_dimensions.height {
|
||||
return Some(size(width, height));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user