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
126 &self,126 &self,
127 style: &EditorStyle,127 style: &EditorStyle,
128 max_height_in_lines: u32,128 max_height_in_lines: u32,
129 y_flipped: bool,
130 window: &mut Window,129 window: &mut Window,
131 cx: &mut Context<Editor>,130 cx: &mut Context<Editor>,
132 ) -> AnyElement {131 ) -> AnyElement {
133 match self {132 match self {
134 CodeContextMenu::Completions(menu) => {133 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)
136 }135 }
137 CodeContextMenu::CodeActions(menu) => {136 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)
139 }138 }
140 }139 }
141 }140 }
@@ -439,7 +438,6 @@ impl CompletionsMenu { · 297 unmodified lines
439 &self,438 &self,
440 style: &EditorStyle,439 style: &EditorStyle,
441 max_height_in_lines: u32,440 max_height_in_lines: u32,
442 y_flipped: bool,
443 window: &mut Window,441 window: &mut Window,
444 cx: &mut Context<Editor>,442 cx: &mut Context<Editor>,
445 ) -> AnyElement {443 ) -> AnyElement {
@@ -589,7 +587,6 @@ impl CompletionsMenu { · 143 unmodified lines
589 .occlude()587 .occlude()
590 .max_h(max_height_in_lines as f32 * window.line_height())588 .max_h(max_height_in_lines as f32 * window.line_height())
591 .track_scroll(self.scroll_handle.clone())589 .track_scroll(self.scroll_handle.clone())
592 .y_flipped(y_flipped)
593 .with_width_from_item(widest_completion_ix)590 .with_width_from_item(widest_completion_ix)
594 .with_sizing_behavior(ListSizingBehavior::Infer);591 .with_sizing_behavior(ListSizingBehavior::Infer);
595 592
@@ -978,7 +975,6 @@ impl CodeActionsMenu { · 382 unmodified lines
978 &self,975 &self,
979 _style: &EditorStyle,976 _style: &EditorStyle,
980 max_height_in_lines: u32,977 max_height_in_lines: u32,
981 y_flipped: bool,
982 window: &mut Window,978 window: &mut Window,
983 cx: &mut Context<Editor>,979 cx: &mut Context<Editor>,
984 ) -> AnyElement {980 ) -> AnyElement {
@@ -1068,7 +1064,6 @@ impl CodeActionsMenu { · 83 unmodified lines
1068 .occlude()1064 .occlude()
1069 .max_h(max_height_in_lines as f32 * window.line_height())1065 .max_h(max_height_in_lines as f32 * window.line_height())
1070 .track_scroll(self.scroll_handle.clone())1066 .track_scroll(self.scroll_handle.clone())
1071 .y_flipped(y_flipped)
1072 .with_width_from_item(1067 .with_width_from_item(
1073 self.actions1068 self.actions
1074 .iter()1069 .iter()
crates/editor/src/editor.rs+1−2
@@ -7702,7 +7702,6 @@ impl Editor { · 7701 unmodified lines
7702 &self,7702 &self,
7703 style: &EditorStyle,7703 style: &EditorStyle,
7704 max_height_in_lines: u32,7704 max_height_in_lines: u32,
7705 y_flipped: bool,
7706 window: &mut Window,7705 window: &mut Window,
7707 cx: &mut Context<Editor>,7706 cx: &mut Context<Editor>,
7708 ) -> Option<AnyElement> {7707 ) -> Option<AnyElement> {
@@ -7711,7 +7710,7 @@ impl Editor { · 2 unmodified lines
7711 if !menu.visible() {7710 if !menu.visible() {
7712 return None;7711 return None;
7713 };7712 };
7714 Some(menu.render(style, max_height_in_lines, y_flipped, window, cx))7713 Some(menu.render(style, max_height_in_lines, window, cx))
7715 }7714 }
7716 7715
7717 fn render_context_menu_aside(7716 fn render_context_menu_aside(
crates/editor/src/element.rs+4−5
@@ -3351,7 +3351,7 @@ impl EditorElement { · 3350 unmodified lines
3351 height - height_above_menu3351 height - height_above_menu
3352 };3352 };
3353 let mut element = self3353 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)
3355 .expect("Visible context menu should always render.");3355 .expect("Visible context menu should always render.");
3356 let size = element.layout_as_root(AvailableSpace::min_size(), window, cx);3356 let size = element.layout_as_root(AvailableSpace::min_size(), window, cx);
3357 Some((CursorPopoverType::CodeContextMenu, element, size))3357 Some((CursorPopoverType::CodeContextMenu, element, size))
@@ -3508,9 +3508,9 @@ impl EditorElement { · 150 unmodified lines
3508 viewport_bounds,3508 viewport_bounds,
3509 window,3509 window,
3510 cx,3510 cx,
3511 move |height, _max_width_for_stable_x, y_flipped, window, cx| {3511 move |height, _max_width_for_stable_x, _, window, cx| {
3512 let mut element = self3512 let mut element = self
3513 .render_context_menu(line_height, height, y_flipped, window, cx)3513 .render_context_menu(line_height, height, window, cx)
3514 .expect("Visible context menu should always render.");3514 .expect("Visible context menu should always render.");
3515 let size = element.layout_as_root(AvailableSpace::min_size(), window, cx);3515 let size = element.layout_as_root(AvailableSpace::min_size(), window, cx);
3516 vec![(CursorPopoverType::CodeContextMenu, element, size)]3516 vec![(CursorPopoverType::CodeContextMenu, element, size)]
@@ -3740,13 +3740,12 @@ impl EditorElement { · 223 unmodified lines
3740 &self,3740 &self,
3741 line_height: Pixels,3741 line_height: Pixels,
3742 height: Pixels,3742 height: Pixels,
3743 y_flipped: bool,
3744 window: &mut Window,3743 window: &mut Window,
3745 cx: &mut App,3744 cx: &mut App,
3746 ) -> Option<AnyElement> {3745 ) -> Option<AnyElement> {
3747 let max_height_in_lines = ((height - POPOVER_Y_PADDING) / line_height).floor() as u32;3746 let max_height_in_lines = ((height - POPOVER_Y_PADDING) / line_height).floor() as u32;
3748 self.editor.update(cx, |editor, cx| {3747 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)
3750 })3749 })
3751 }3750 }
3752 3751

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