Pass max height manually

This commit is contained in:
Antonio Scandurra 2023-11-27 14:56:46 +01:00
parent 682712f132
commit eb647be685
2 changed files with 24 additions and 14 deletions

View File

@ -906,12 +906,16 @@ impl ContextMenu {
&self, &self,
cursor_position: DisplayPoint, cursor_position: DisplayPoint,
style: &EditorStyle, style: &EditorStyle,
max_height: Pixels,
workspace: Option<WeakView<Workspace>>, workspace: Option<WeakView<Workspace>>,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> (DisplayPoint, AnyElement) { ) -> (DisplayPoint, AnyElement) {
match self { match self {
ContextMenu::Completions(menu) => (cursor_position, menu.render(style, workspace, cx)), ContextMenu::Completions(menu) => (
ContextMenu::CodeActions(menu) => menu.render(cursor_position, style, cx), 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( fn render(
&self, &self,
style: &EditorStyle, style: &EditorStyle,
max_height: Pixels,
workspace: Option<WeakView<Workspace>>, workspace: Option<WeakView<Workspace>>,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> AnyElement { ) -> AnyElement {
@ -1256,7 +1261,7 @@ impl CompletionsMenu {
let multiline_docs = { let multiline_docs = {
let mat = &self.matches[selected_item]; 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(Documentation::MultiLinePlainText(text)) => {
Some(div().child(SharedString::from(text.clone()))) Some(div().child(SharedString::from(text.clone())))
} }
@ -1264,7 +1269,12 @@ impl CompletionsMenu {
render_parsed_markdown("completions_markdown", parsed, &style, workspace, cx), render_parsed_markdown("completions_markdown", parsed, &style, workspace, cx),
)), )),
_ => None, _ => None,
} };
multiline_docs.map(|div| {
div.id("multiline_docs")
.max_h(max_height)
.overflow_y_scroll()
})
}; };
let list = uniform_list( let list = uniform_list(
cx.view().clone(), cx.view().clone(),
@ -1341,13 +1351,14 @@ impl CompletionsMenu {
.collect() .collect()
}, },
) )
.max_h(max_height)
.track_scroll(self.scroll_handle.clone()) .track_scroll(self.scroll_handle.clone())
.with_width_from_item(widest_completion_ix); .with_width_from_item(widest_completion_ix);
Popover::new() Popover::new()
.child(list) .child(list)
.when_some(multiline_docs, |popover, multiline_docs| { .when_some(multiline_docs, |popover, multiline_docs| {
popover.aside(multiline_docs.id("multiline_docs").overflow_y_scroll()) popover.aside(multiline_docs)
}) })
.into_any_element() .into_any_element()
} }
@ -1466,6 +1477,7 @@ impl CodeActionsMenu {
&self, &self,
mut cursor_position: DisplayPoint, mut cursor_position: DisplayPoint,
style: &EditorStyle, style: &EditorStyle,
max_height: Pixels,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> (DisplayPoint, AnyElement) { ) -> (DisplayPoint, AnyElement) {
let actions = self.actions.clone(); let actions = self.actions.clone();
@ -1520,6 +1532,7 @@ impl CodeActionsMenu {
.elevation_1(cx) .elevation_1(cx)
.px_2() .px_2()
.py_1() .py_1()
.max_h(max_height)
.track_scroll(self.scroll_handle.clone()) .track_scroll(self.scroll_handle.clone())
.with_width_from_item( .with_width_from_item(
self.actions self.actions
@ -4377,12 +4390,14 @@ impl Editor {
&self, &self,
cursor_position: DisplayPoint, cursor_position: DisplayPoint,
style: &EditorStyle, style: &EditorStyle,
max_height: Pixels,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> Option<(DisplayPoint, AnyElement)> { ) -> Option<(DisplayPoint, AnyElement)> {
self.context_menu.read().as_ref().map(|menu| { self.context_menu.read().as_ref().map(|menu| {
menu.render( menu.render(
cursor_position, cursor_position,
style, style,
max_height,
self.workspace.as_ref().map(|(w, _)| w.clone()), self.workspace.as_ref().map(|(w, _)| w.clone()),
cx, cx,
) )

View File

@ -1026,14 +1026,8 @@ impl EditorElement {
if let Some((position, mut context_menu)) = layout.context_menu.take() { if let Some((position, mut context_menu)) = layout.context_menu.take() {
cx.with_z_index(1, |cx| { cx.with_z_index(1, |cx| {
let line_height = self.style.text.line_height_in_pixels(cx.rem_size()); let available_space =
let available_space = size( size(AvailableSpace::MinContent, AvailableSpace::MinContent);
AvailableSpace::MinContent,
AvailableSpace::Definite(
(12. * line_height)
.min((text_bounds.size.height - line_height) / 2.),
),
);
let context_menu_size = context_menu.measure(available_space, cx); let context_menu_size = context_menu.measure(available_space, cx);
let cursor_row_layout = &layout.position_map.line_layouts 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 let Some(newest_selection_head) = newest_selection_head {
if (start_row..end_row).contains(&newest_selection_head.row()) { if (start_row..end_row).contains(&newest_selection_head.row()) {
if editor.context_menu_visible() { if editor.context_menu_visible() {
let max_height = (12. * line_height).min((bounds.size.height - line_height) / 2.);
context_menu = 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!( let active = matches!(