History

Use consistent ordering for popup menus (#27765)

Before this change, the editor completion menu and gutter menus reversed their order so that the initial selection is near the user's focus. This change instead displays these menus in a consistent top-to-bottom order because the following benefits outweigh that benefit: * Matches behavior of some other editors (Neovim and VSCode). * Looks better for lexicographic lists. * Keeps the meaning of keyboard interaction consistent, if the user is anticipating the order of the menu's contents. Could consider making this configurable in the future if desired. Closes #25066. Release Notes: - N/A

Aaron Feickert committed 1 year ago

Commit 7bc62de1 parent f3adf413 files · +7 −14Browse files

Unified · Split

3 files
  1. crates/editor/src/code_context_menus.rs +2 −7
  2. crates/editor/src/editor.rs +1 −2
  3. crates/editor/src/element.rs +4 −5
crates/editor/src/code_context_menus.rs+2−7
@@ -126,16 +126,15 @@ impl CodeContextMenu { · 125 unmodified lines
126126 &self,
127127 style: &EditorStyle,
128128 max_height_in_lines: u32,
129− y_flipped: bool,
130129 window: &mut Window,
131130 cx: &mut Context<Editor>,
132131 ) -> AnyElement {
133132 match self {
134133 CodeContextMenu::Completions(menu) => {
135− menu.render(style, max_height_in_lines, y_flipped, window, cx)
134+ menu.render(style, max_height_in_lines, window, cx)
136135 }
137136 CodeContextMenu::CodeActions(menu) => {
138− menu.render(style, max_height_in_lines, y_flipped, window, cx)
137+ menu.render(style, max_height_in_lines, window, cx)
139138 }
140139 }
141140 }
@@ -439,7 +438,6 @@ impl CompletionsMenu { · 297 unmodified lines
439438 &self,
440439 style: &EditorStyle,
441440 max_height_in_lines: u32,
442− y_flipped: bool,
443441 window: &mut Window,
444442 cx: &mut Context<Editor>,
445443 ) -> AnyElement {
@@ -589,7 +587,6 @@ impl CompletionsMenu { · 143 unmodified lines
589587 .occlude()
590588 .max_h(max_height_in_lines as f32 * window.line_height())
591589 .track_scroll(self.scroll_handle.clone())
592− .y_flipped(y_flipped)
593590 .with_width_from_item(widest_completion_ix)
594591 .with_sizing_behavior(ListSizingBehavior::Infer);
595592
@@ -978,7 +975,6 @@ impl CodeActionsMenu { · 382 unmodified lines
978975 &self,
979976 _style: &EditorStyle,
980977 max_height_in_lines: u32,
981− y_flipped: bool,
982978 window: &mut Window,
983979 cx: &mut Context<Editor>,
984980 ) -> AnyElement {
@@ -1068,7 +1064,6 @@ impl CodeActionsMenu { · 83 unmodified lines
10681064 .occlude()
10691065 .max_h(max_height_in_lines as f32 * window.line_height())
10701066 .track_scroll(self.scroll_handle.clone())
1071− .y_flipped(y_flipped)
10721067 .with_width_from_item(
10731068 self.actions
10741069 .iter()
crates/editor/src/editor.rs+1−2
@@ -7702,7 +7702,6 @@ impl Editor { · 7701 unmodified lines
77027702 &self,
77037703 style: &EditorStyle,
77047704 max_height_in_lines: u32,
7705− y_flipped: bool,
77067705 window: &mut Window,
77077706 cx: &mut Context<Editor>,
77087707 ) -> Option<AnyElement> {
@@ -7711,7 +7710,7 @@ impl Editor { · 2 unmodified lines
77117710 if !menu.visible() {
77127711 return None;
77137712 };
7714− Some(menu.render(style, max_height_in_lines, y_flipped, window, cx))
7713+ Some(menu.render(style, max_height_in_lines, window, cx))
77157714 }
77167715
77177716 fn render_context_menu_aside(
crates/editor/src/element.rs+4−5
@@ -3351,7 +3351,7 @@ impl EditorElement { · 3350 unmodified lines
33513351 height - height_above_menu
33523352 };
33533353 let mut element = self
3354− .render_context_menu(line_height, menu_height, y_flipped, window, cx)
3354+ .render_context_menu(line_height, menu_height, window, cx)
33553355 .expect("Visible context menu should always render.");
33563356 let size = element.layout_as_root(AvailableSpace::min_size(), window, cx);
33573357 Some((CursorPopoverType::CodeContextMenu, element, size))
@@ -3508,9 +3508,9 @@ impl EditorElement { · 150 unmodified lines
35083508 viewport_bounds,
35093509 window,
35103510 cx,
3511− move |height, _max_width_for_stable_x, y_flipped, window, cx| {
3511+ move |height, _max_width_for_stable_x, _, window, cx| {
35123512 let mut element = self
3513− .render_context_menu(line_height, height, y_flipped, window, cx)
3513+ .render_context_menu(line_height, height, window, cx)
35143514 .expect("Visible context menu should always render.");
35153515 let size = element.layout_as_root(AvailableSpace::min_size(), window, cx);
35163516 vec![(CursorPopoverType::CodeContextMenu, element, size)]
@@ -3740,13 +3740,12 @@ impl EditorElement { · 223 unmodified lines
37403740 &self,
37413741 line_height: Pixels,
37423742 height: Pixels,
3743− y_flipped: bool,
37443743 window: &mut Window,
37453744 cx: &mut App,
37463745 ) -> Option<AnyElement> {
37473746 let max_height_in_lines = ((height - POPOVER_Y_PADDING) / line_height).floor() as u32;
37483747 self.editor.update(cx, |editor, cx| {
3749− editor.render_context_menu(&self.style, max_height_in_lines, y_flipped, window, cx)
3748+ editor.render_context_menu(&self.style, max_height_in_lines, window, cx)
37503749 })
37513750 }
37523751

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t