This commit is contained in:
Aaron Ang 2026-05-31 02:55:34 +01:00 committed by GitHub
commit f3057c9f4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 24 deletions

View file

@ -307,14 +307,14 @@
//
// 1. Show the scrollbar if there's important information or
// follow the system's configured behavior
// "auto"
// "auto" (default)
// 2. Match the system's configured behavior:
// "system"
// 3. Always show the scrollbar:
// "always"
// 4. Never show the scrollbar:
// "never" (default)
"completion_menu_scrollbar": "never",
// "never"
"completion_menu_scrollbar": "auto",
// Whether to align detail text in code completions context menus left or right.
"completion_detail_alignment": "left",
// How to display the LSP item kind (function, method, variable, etc.)

View file

@ -3726,17 +3726,17 @@ impl EditorElement {
) -> Option<ContextMenuLayout> {
let mut min_menu_height = Pixels::ZERO;
let mut max_menu_height = Pixels::ZERO;
let mut height_above_menu = Pixels::ZERO;
let height_below_menu = Pixels::ZERO;
let mut edit_prediction_height = Pixels::ZERO;
let mut edit_prediction_popover_visible = false;
let mut context_menu_visible = false;
let context_menu_placement;
let menu_line_height = self.context_menu_line_height(window);
{
let editor = self.editor.read(cx);
if editor.edit_prediction_visible_in_cursor_popover(editor.has_active_edit_prediction())
{
height_above_menu +=
edit_prediction_height +=
editor.edit_prediction_cursor_popover_height() + POPOVER_Y_PADDING;
edit_prediction_popover_visible = true;
}
@ -3751,8 +3751,10 @@ impl EditorElement {
(options.min_entries_visible, options.max_entries_visible)
});
min_menu_height += line_height * min_height_in_lines as f32 + POPOVER_Y_PADDING;
max_menu_height += line_height * max_height_in_lines as f32 + POPOVER_Y_PADDING;
min_menu_height +=
menu_line_height * min_height_in_lines as f32 + POPOVER_Y_PADDING;
max_menu_height +=
menu_line_height * max_height_in_lines as f32 + POPOVER_Y_PADDING;
context_menu_visible = true;
}
context_menu_placement = editor
@ -3792,8 +3794,13 @@ impl EditorElement {
..Default::default()
});
let min_height = height_above_menu + min_menu_height + height_below_menu;
let max_height = height_above_menu + max_menu_height + height_below_menu;
let popover_gap = if edit_prediction_popover_visible && context_menu_visible {
MENU_GAP
} else {
Pixels::ZERO
};
let min_height = edit_prediction_height + min_menu_height + popover_gap;
let max_height = edit_prediction_height + max_menu_height + popover_gap;
let (laid_out_popovers, y_flipped) = self.layout_popovers_above_or_below_line(
target_position,
line_height,
@ -3804,16 +3811,12 @@ impl EditorElement {
viewport_bounds,
window,
cx,
|height, max_width_for_stable_x, y_flipped, window, cx| {
|height, max_width_for_stable_x, _y_flipped, window, cx| {
// First layout the menu to get its size - others can be at least this wide.
let context_menu = if context_menu_visible {
let menu_height = if y_flipped {
height - height_below_menu
} else {
height - height_above_menu
};
let menu_height = height - edit_prediction_height - popover_gap;
let mut element = self
.render_context_menu(line_height, menu_height, window, cx)
.render_context_menu(menu_line_height, menu_height, window, cx)
.expect("Visible context menu should always render.");
let size = element.layout_as_root(AvailableSpace::min_size(), window, cx);
Some((CursorPopoverType::CodeContextMenu, element, size))
@ -3964,8 +3967,9 @@ impl EditorElement {
(options.min_entries_visible, options.max_entries_visible)
});
let min_height = line_height * min_height_in_lines as f32 + POPOVER_Y_PADDING;
let max_height = line_height * max_height_in_lines as f32 + POPOVER_Y_PADDING;
let menu_line_height = self.context_menu_line_height(window);
let min_height = menu_line_height * min_height_in_lines as f32 + POPOVER_Y_PADDING;
let max_height = menu_line_height * max_height_in_lines as f32 + POPOVER_Y_PADDING;
let viewport_bounds =
Bounds::new(Default::default(), window.viewport_size()).extend(Edges {
right: -right_margin - MENU_GAP,
@ -3986,7 +3990,7 @@ impl EditorElement {
cx,
move |height, _max_width_for_stable_x, _, window, cx| {
let mut element = self
.render_context_menu(line_height, height, window, cx)
.render_context_menu(menu_line_height, height, window, cx)
.expect("Visible context menu should always render.");
let size = element.layout_as_root(AvailableSpace::min_size(), window, cx);
vec![(CursorPopoverType::CodeContextMenu, element, size)]
@ -4052,9 +4056,9 @@ impl EditorElement {
}
None => {
if available_below > min_height {
(false, min_height)
(false, cmp::min(max_height, available_below))
} else if available_above > min_height {
(true, min_height)
(true, cmp::min(max_height, available_above))
} else if available_above > available_below {
(true, available_above)
} else {
@ -4212,6 +4216,14 @@ impl EditorElement {
None
}
// Menu rows render at Comfortable line height regardless of the editor's buffer_line_height
// (see the text-style override in layout_popovers_above_or_below_line). Budget calculations
// and the lines→pixels floor must use this same value so they stay consistent.
fn context_menu_line_height(&self, window: &Window) -> Pixels {
self.style.text.font_size.to_pixels(window.rem_size())
* BufferLineHeight::Comfortable.value()
}
fn render_context_menu(
&self,
line_height: Pixels,

View file

@ -235,13 +235,13 @@ pub struct EditorSettingsContent {
///
/// 1. Show the scrollbar if there's important information or
/// follow the system's configured behavior
/// "auto"
/// "auto" (default)
/// 2. Match the system's configured behavior:
/// "system"
/// 3. Always show the scrollbar:
/// "always"
/// 4. Never show the scrollbar:
/// "never" (default)
/// "never"
pub completion_menu_scrollbar: Option<ShowScrollbar>,
/// Whether to align detail text in code completions context menus left or right.