From fce31b7ddfde208ea79f730d2cf5003983a37dfa Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 22 Dec 2023 10:50:33 +0200 Subject: [PATCH 1/3] Remove the warnings from element.rs --- crates/editor2/src/element.rs | 103 +++++++++++++++------------------- 1 file changed, 45 insertions(+), 58 deletions(-) diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index 9dab9d00ae..d97883beba 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -493,8 +493,8 @@ impl EditorElement { event: &MouseMoveEvent, position_map: &PositionMap, text_bounds: Bounds, - gutter_bounds: Bounds, - stacking_order: &StackingOrder, + _gutter_bounds: Bounds, + _stacking_order: &StackingOrder, cx: &mut ViewContext, ) { 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, - cx: &mut WindowContext, - ) -> LayoutState { + fn compute_layout(&mut self, bounds: Bounds, cx: &mut WindowContext) -> LayoutState { self.editor.update(cx, |editor, cx| { let snapshot = editor.snapshot(cx); let style = self.style.clone(); @@ -1811,22 +1806,23 @@ impl EditorElement { let text_width = bounds.size.width - gutter_width; let overscroll = size(em_width, px(0.)); - let snapshot = { - editor.set_visible_line_count((bounds.size.height / line_height).into(), cx); + // todo!() + // 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; - let wrap_width = match editor.soft_wrap_mode(cx) { - SoftWrap::None => (MAX_LINE_LEN / 2) as f32 * em_advance, - SoftWrap::EditorWidth => editor_width, - SoftWrap::Column(column) => editor_width.min(column as f32 * em_advance), - }; + // let editor_width = text_width - gutter_margin - overscroll.width - em_width; + // let wrap_width = match editor.soft_wrap_mode(cx) { + // SoftWrap::None => (MAX_LINE_LEN / 2) as f32 * em_advance, + // SoftWrap::EditorWidth => editor_width, + // SoftWrap::Column(column) => editor_width.min(column as f32 * em_advance), + // }; - if editor.set_wrap_width(Some(wrap_width), cx) { - editor.snapshot(cx) - } else { - snapshot - } - }; + // if editor.set_wrap_width(Some(wrap_width), cx) { + // editor.snapshot(cx) + // } else { + // snapshot + // } + // }; let wrap_guides = editor .wrap_guides(cx) @@ -1834,7 +1830,6 @@ impl EditorElement { .map(|(guide, active)| (self.column_pixels(*guide, cx), *active)) .collect::>(); - 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 +2096,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 +2105,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 +2207,6 @@ impl EditorElement { cx: &mut ViewContext, ) -> (Pixels, Vec) { 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::, _>(|(_, block)| match block { @@ -2220,11 +2214,11 @@ impl EditorElement { TransformBlock::Custom(block) => block.style() == BlockStyle::Fixed, }); - let mut render_block = |block: &TransformBlock, - available_space: Size, - block_id: usize, - editor: &mut Editor, - cx: &mut ViewContext| { + let render_block = |block: &TransformBlock, + available_space: Size, + block_id: usize, + editor: &mut Editor, + cx: &mut ViewContext| { let mut element = match block { TransformBlock::Custom(block) => { let align_to = block @@ -2277,7 +2271,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,8 +2290,6 @@ 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") @@ -2336,7 +2328,6 @@ impl EditorElement { })), // .p_x(gutter_padding) ) } else { - let text_style = style.text.clone(); h_stack() .id("collapsed context") .size_full() @@ -2447,7 +2438,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 +2754,7 @@ impl Element for EditorElement { fn layout( &mut self, - element_state: Option, + _element_state: Option, cx: &mut gpui::WindowContext, ) -> (gpui::LayoutId, Self::State) { self.editor.update(cx, |editor, cx| { @@ -2782,22 +2772,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 +2801,7 @@ impl Element for EditorElement { fn paint( &mut self, bounds: Bounds, - element_state: &mut Self::State, + _element_state: &mut Self::State, cx: &mut gpui::WindowContext, ) { let editor = self.editor.clone(); @@ -3137,7 +3124,7 @@ impl HighlightedRange { &self, start_y: Pixels, lines: &[HighlightedRangeLine], - bounds: Bounds, + _bounds: Bounds, cx: &mut WindowContext, ) { if lines.is_empty() { @@ -3755,7 +3742,7 @@ fn compute_auto_height_layout( known_dimensions: Size>, cx: &mut ViewContext, ) -> Option> { - let mut width = known_dimensions.width?; + let width = known_dimensions.width?; if let Some(height) = known_dimensions.height { return Some(size(width, height)); } From d36ec81725009745e65418a28a76425c107683ae Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 22 Dec 2023 11:55:25 +0200 Subject: [PATCH 2/3] Move multibuffer "go to file" button into the buffer header Co-Authored-By: Antonio Scandurra --- crates/editor2/src/element.rs | 101 +++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index d97883beba..c6d468f40b 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -2290,46 +2290,55 @@ impl EditorElement { .map(|p| SharedString::from(p.to_string_lossy().to_string() + "/")); } - 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 { h_stack() - .id("collapsed context") + .id(("collapsed context", block_id)) .size_full() .gap(gutter_padding) .child( @@ -2834,17 +2843,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); }); }); From 4d5ff77abee0a7f0891fe95fcdc200e7a454a630 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 22 Dec 2023 12:14:53 +0200 Subject: [PATCH 3/3] Fix the tests --- crates/editor2/src/element.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index c6d468f40b..294cc2c4e3 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -1806,23 +1806,22 @@ impl EditorElement { let text_width = bounds.size.width - gutter_width; let overscroll = size(em_width, px(0.)); - // todo!() - // let snapshot = { - // editor.set_visible_line_count((bounds.size.height / line_height).into(), cx); + 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; - // let wrap_width = match editor.soft_wrap_mode(cx) { - // SoftWrap::None => (MAX_LINE_LEN / 2) as f32 * em_advance, - // SoftWrap::EditorWidth => editor_width, - // SoftWrap::Column(column) => editor_width.min(column as f32 * em_advance), - // }; + let editor_width = text_width - gutter_margin - overscroll.width - em_width; + let wrap_width = match editor.soft_wrap_mode(cx) { + SoftWrap::None => (MAX_LINE_LEN / 2) as f32 * em_advance, + SoftWrap::EditorWidth => editor_width, + SoftWrap::Column(column) => editor_width.min(column as f32 * em_advance), + }; - // if editor.set_wrap_width(Some(wrap_width), cx) { - // editor.snapshot(cx) - // } else { - // snapshot - // } - // }; + if editor.set_wrap_width(Some(wrap_width), cx) { + editor.snapshot(cx) + } else { + snapshot + } + }; let wrap_guides = editor .wrap_guides(cx)