From eb647be685e7d37995dc42bdf2bdf7689d1aeb5e Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 27 Nov 2023 14:56:46 +0100 Subject: [PATCH] Pass max height manually --- crates/editor2/src/editor.rs | 25 ++++++++++++++++++++----- crates/editor2/src/element.rs | 13 ++++--------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index aa34f9ec47..451a3c6535 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -906,12 +906,16 @@ impl ContextMenu { &self, cursor_position: DisplayPoint, style: &EditorStyle, + max_height: Pixels, workspace: Option>, cx: &mut ViewContext, ) -> (DisplayPoint, AnyElement) { match self { - ContextMenu::Completions(menu) => (cursor_position, menu.render(style, workspace, cx)), - ContextMenu::CodeActions(menu) => menu.render(cursor_position, style, cx), + ContextMenu::Completions(menu) => ( + cursor_position, + menu.render(style, max_height, workspace, cx), + ), + ContextMenu::CodeActions(menu) => menu.render(cursor_position, style, max_height, cx), } } } @@ -1223,6 +1227,7 @@ impl CompletionsMenu { fn render( &self, style: &EditorStyle, + max_height: Pixels, workspace: Option>, cx: &mut ViewContext, ) -> AnyElement { @@ -1256,7 +1261,7 @@ impl CompletionsMenu { let multiline_docs = { let mat = &self.matches[selected_item]; - match &self.completions.read()[mat.candidate_id].documentation { + let multiline_docs = match &self.completions.read()[mat.candidate_id].documentation { Some(Documentation::MultiLinePlainText(text)) => { Some(div().child(SharedString::from(text.clone()))) } @@ -1264,7 +1269,12 @@ impl CompletionsMenu { render_parsed_markdown("completions_markdown", parsed, &style, workspace, cx), )), _ => None, - } + }; + multiline_docs.map(|div| { + div.id("multiline_docs") + .max_h(max_height) + .overflow_y_scroll() + }) }; let list = uniform_list( cx.view().clone(), @@ -1341,13 +1351,14 @@ impl CompletionsMenu { .collect() }, ) + .max_h(max_height) .track_scroll(self.scroll_handle.clone()) .with_width_from_item(widest_completion_ix); Popover::new() .child(list) .when_some(multiline_docs, |popover, multiline_docs| { - popover.aside(multiline_docs.id("multiline_docs").overflow_y_scroll()) + popover.aside(multiline_docs) }) .into_any_element() } @@ -1466,6 +1477,7 @@ impl CodeActionsMenu { &self, mut cursor_position: DisplayPoint, style: &EditorStyle, + max_height: Pixels, cx: &mut ViewContext, ) -> (DisplayPoint, AnyElement) { let actions = self.actions.clone(); @@ -1520,6 +1532,7 @@ impl CodeActionsMenu { .elevation_1(cx) .px_2() .py_1() + .max_h(max_height) .track_scroll(self.scroll_handle.clone()) .with_width_from_item( self.actions @@ -4377,12 +4390,14 @@ impl Editor { &self, cursor_position: DisplayPoint, style: &EditorStyle, + max_height: Pixels, cx: &mut ViewContext, ) -> Option<(DisplayPoint, AnyElement)> { self.context_menu.read().as_ref().map(|menu| { menu.render( cursor_position, style, + max_height, self.workspace.as_ref().map(|(w, _)| w.clone()), cx, ) diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index c6035e8734..e591dd84cf 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -1026,14 +1026,8 @@ impl EditorElement { if let Some((position, mut context_menu)) = layout.context_menu.take() { cx.with_z_index(1, |cx| { - let line_height = self.style.text.line_height_in_pixels(cx.rem_size()); - let available_space = size( - AvailableSpace::MinContent, - AvailableSpace::Definite( - (12. * line_height) - .min((text_bounds.size.height - line_height) / 2.), - ), - ); + let available_space = + size(AvailableSpace::MinContent, AvailableSpace::MinContent); let context_menu_size = context_menu.measure(available_space, cx); let cursor_row_layout = &layout.position_map.line_layouts @@ -1978,8 +1972,9 @@ impl EditorElement { if let Some(newest_selection_head) = newest_selection_head { if (start_row..end_row).contains(&newest_selection_head.row()) { if editor.context_menu_visible() { + let max_height = (12. * line_height).min((bounds.size.height - line_height) / 2.); context_menu = - editor.render_context_menu(newest_selection_head, &self.style, cx); + editor.render_context_menu(newest_selection_head, &self.style, max_height, cx); } let active = matches!(