Skip to content

Commit 2e302b1

Browse files
danilo-lealagu-ziamnbutler
authored
context menu: Improve docs aside responsiveness (#25347)
Closes #24883 While this PR closes the issue above, it still doesn't implement a bullet-proof solution for the context menu docs aside, meaning, it might not work the best way if there are other places using it (like the Editor Controls menu). For that, I think we'll want a more robust collision-aware solution, possibly similar to the LSP completion menu. Release Notes: - N/A --------- Co-authored-by: Agus Zubiaga <[email protected]> Co-authored-by: Nate Butler <[email protected]>
1 parent 17323ed commit 2e302b1

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

crates/inline_completion_button/src/inline_completion_button.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,14 @@ impl InlineCompletionButton {
399399
})
400400
}
401401

402-
pub fn build_language_settings_menu(&self, mut menu: ContextMenu, cx: &mut App) -> ContextMenu {
402+
pub fn build_language_settings_menu(
403+
&self,
404+
mut menu: ContextMenu,
405+
window: &Window,
406+
cx: &mut App,
407+
) -> ContextMenu {
403408
let fs = self.fs.clone();
409+
let line_height = window.line_height();
404410

405411
menu = menu.header("Show Edit Predictions For");
406412

@@ -499,12 +505,14 @@ impl InlineCompletionButton {
499505
)
500506
.child(
501507
h_flex()
508+
.items_start()
502509
.pt_2()
510+
.flex_1()
503511
.gap_1p5()
504512
.border_t_1()
505513
.border_color(cx.theme().colors().border_variant)
506-
.child(Icon::new(icon_name).size(IconSize::XSmall).color(icon_color))
507-
.child(div().child(Label::new(msg).size(LabelSize::Small).color(label_color)))
514+
.child(h_flex().flex_shrink_0().h(line_height).child(Icon::new(icon_name).size(IconSize::XSmall).color(icon_color)))
515+
.child(div().child(msg).w_full().text_sm().text_color(label_color.color(cx)))
508516
)
509517
.into_any_element()
510518
})
@@ -631,8 +639,8 @@ impl InlineCompletionButton {
631639
window: &mut Window,
632640
cx: &mut Context<Self>,
633641
) -> Entity<ContextMenu> {
634-
ContextMenu::build(window, cx, |menu, _, cx| {
635-
self.build_language_settings_menu(menu, cx)
642+
ContextMenu::build(window, cx, |menu, window, cx| {
643+
self.build_language_settings_menu(menu, window, cx)
636644
.separator()
637645
.link(
638646
"Go to Copilot Settings",
@@ -650,8 +658,8 @@ impl InlineCompletionButton {
650658
window: &mut Window,
651659
cx: &mut Context<Self>,
652660
) -> Entity<ContextMenu> {
653-
ContextMenu::build(window, cx, |menu, _, cx| {
654-
self.build_language_settings_menu(menu, cx)
661+
ContextMenu::build(window, cx, |menu, window, cx| {
662+
self.build_language_settings_menu(menu, window, cx)
655663
.separator()
656664
.action("Sign Out", supermaven::SignOut.boxed_clone())
657665
})
@@ -662,8 +670,8 @@ impl InlineCompletionButton {
662670
window: &mut Window,
663671
cx: &mut Context<Self>,
664672
) -> Entity<ContextMenu> {
665-
ContextMenu::build(window, cx, |menu, _window, cx| {
666-
self.build_language_settings_menu(menu, cx).when(
673+
ContextMenu::build(window, cx, |menu, window, cx| {
674+
self.build_language_settings_menu(menu, window, cx).when(
667675
cx.has_flag::<PredictEditsRateCompletionsFeatureFlag>(),
668676
|this| this.action("Rate Completions", RateCompletions.boxed_clone()),
669677
)

crates/ui/src/components/context_menu.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,26 +507,33 @@ impl ContextMenuItem {
507507
impl Render for ContextMenu {
508508
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
509509
let ui_font_size = ThemeSettings::get_global(cx).ui_font_size(cx);
510+
let window_size = window.viewport_size();
511+
let rem_size = window.rem_size();
512+
let is_wide_window = window_size.width / rem_size > rems_from_px(800.).0;
510513

511514
let aside = self
512515
.documentation_aside
513516
.as_ref()
514517
.map(|(_, callback)| callback.clone());
515518

516519
h_flex()
520+
.when(is_wide_window, |this| {this.flex_row()})
521+
.when(!is_wide_window, |this| {this.flex_col()})
517522
.w_full()
518523
.items_start()
519524
.gap_1()
520-
.when_some(aside, |this, aside| {
521-
this.child(
525+
.child(
526+
div().children(aside.map(|aside|
522527
WithRemSize::new(ui_font_size)
523528
.occlude()
524529
.elevation_2(cx)
525530
.p_2()
526-
.max_w_96()
527-
.child(aside(cx)),
528-
)
529-
})
531+
.overflow_hidden()
532+
.when(is_wide_window, |this| {this.max_w_96()})
533+
.when(!is_wide_window, |this| {this.max_w_48()})
534+
.child(aside(cx))
535+
))
536+
)
530537
.child(
531538
WithRemSize::new(ui_font_size)
532539
.occlude()

0 commit comments

Comments
 (0)