BlueGit

ict rusty-teams

fix(chat): right-click menu turns upside down at the bottom edge

- When the list does not fit below the cursor it ends at the cursor and the reactions sit below it
- The list height is measured on the first (still invisible) animation frame

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-11 · 2 weeks ago

Hash
7e20b11feb522f2a58aa7d69e203fef9bf89c7fa
Parent
39754cdd
1 file changed +40 −10
crates/app/src/views/message_context_menu.rs +40 −10
@@ -5,6 +5,7 @@ use std::time::Duration;
5 5 use gpui_kit::base::{GlobalState, POPUP_PRIORITY};
6 6 use gpui_kit::component::menu::PopupMenu;
7 7 use gpui_kit::component::h_flex;
8 use gpui_kit::prelude::FluentBuilder as _;
8 9 use gpui_kit::*;
9 10
10 11 use super::message_actions::{MenuActions, MessageMenu, picker_button, reaction_button};
@@ -32,6 +33,7 @@ pub struct OpenContextMenu {
32 33 pub serial: u64,
33 34 popup: Rc<RefCell<Option<(Entity<PopupMenu>, Subscription)>>>,
34 35 bar_pressed: Rc<Cell<bool>>,
36 list_height: Rc<Cell<Option<f32>>>,
35 37 }
36 38
37 39 impl OpenContextMenu {
@@ -42,6 +44,7 @@ impl OpenContextMenu {
42 44 serial,
43 45 popup: Rc::default(),
44 46 bar_pressed: Rc::default(),
47 list_height: Rc::default(),
45 48 }
46 49 }
47 50
@@ -65,6 +68,15 @@ impl OpenContextMenu {
65 68 }
66 69 }
67 70
71 fn measure_height(height: Rc<Cell<Option<f32>>>) -> impl IntoElement {
72 canvas(
73 move |bounds, _, _| height.set(Some(f32::from(bounds.size.height))),
74 |_, _, _, _| {},
75 )
76 .absolute()
77 .size_full()
78 }
79
68 80 fn animated_reaction(button: AnyElement, index: usize, serial: u64) -> AnyElement {
69 81 let delay = REACTION_STAGGER * index as u32;
70 82 let total = delay + REACTION_OPEN;
@@ -83,7 +95,7 @@ fn animated_reaction(button: AnyElement, index: usize, serial: u64) -> AnyElemen
83 95 .into_any_element()
84 96 }
85 97
86 /// Telegram's behaviour in our look: the menu opens at the cursor (flipped above it near the bottom edge), quick reactions sit on top of it.
98 /// Telegram's behaviour in our look: reactions above the cursor, the menu below; near the bottom edge it turns upside down.
87 99 pub fn message_context_menu(
88 100 mut menu: MessageMenu,
89 101 open: &OpenContextMenu,
@@ -107,13 +119,24 @@ pub fn message_context_menu(
107 119 .map(|(index, glyph)| animated_reaction(reaction_button(&menu, glyph, index), index, serial))
108 120 .collect();
109 121 reactions.push(animated_reaction(picker_button(&menu, cx), menu.quick.len(), serial));
122 let viewport_height = f32::from(window.viewport_size().height);
123 let cursor_y = f32::from(open.position.y);
124 let upside_down = open
125 .list_height
126 .get()
127 .is_some_and(|height| cursor_y + height + WINDOW_MARGIN > viewport_height);
110 128 let bar_pressed = open.bar_pressed.clone();
111 129 let bar = h_flex()
112 130 .debug_selector(|| format!("{CONTEXT_MENU_TAG}/reactions").into())
113 131 .absolute()
114 132 .left_0()
115 .bottom_full()
116 .mb(px(PANEL_GAP))
133 .map(|bar| {
134 if upside_down {
135 bar.top_full().mt(px(PANEL_GAP))
136 } else {
137 bar.bottom_full().mb(px(PANEL_GAP))
138 }
139 })
117 140 .occlude()
118 141 .on_scroll_wheel(|_, _, cx| cx.stop_propagation())
119 142 .h(px(TOOLBAR_HEIGHT))
@@ -127,21 +150,28 @@ pub fn message_context_menu(
127 150 GlobalState::suppress_text_selection(cx);
128 151 })
129 152 .children(reactions);
153 let slide = if upside_down { LIST_SLIDE } else { -LIST_SLIDE };
130 154 let list = div()
131 155 .relative()
132 156 .debug_selector(|| format!("{CONTEXT_MENU_TAG}/list").into())
133 157 .child(popup)
158 .child(measure_height(open.list_height.clone()))
134 159 .with_animation(
135 ElementId::Name(format!("context-list-{serial}").into()),
160 ElementId::Name(format!("context-list-{serial}-{upside_down}").into()),
136 161 Animation::new(LIST_OPEN).with_easing(ease_out_quint()),
137 |element, delta| element.opacity(delta).top(px((delta - 1.) * LIST_SLIDE)),
162 move |element, delta| element.opacity(delta).top(px((1. - delta) * slide)),
138 163 );
139 let anchor_at = point(
140 open.position.x,
141 open.position.y.max(px(BAR_LIFT + WINDOW_MARGIN)),
142 );
164 let (anchor_at, corner) = if upside_down {
165 let lowest = viewport_height - WINDOW_MARGIN - BAR_LIFT;
166 (point(open.position.x, px(cursor_y.min(lowest))), Anchor::BottomLeft)
167 } else {
168 (
169 point(open.position.x, open.position.y.max(px(BAR_LIFT + WINDOW_MARGIN))),
170 Anchor::TopLeft,
171 )
172 };
143 173 deferred(
144 anchored().position(anchor_at).child(
174 anchored().position(anchor_at).anchor(corner).child(
145 175 div()
146 176 .id(ElementId::Name(format!("{CONTEXT_MENU_TAG}-{}", open.key).into()))
147 177 .debug_selector(|| CONTEXT_MENU_TAG.into())
@@ -5,6 +5,7 @@ use std::time::Duration;
5use gpui_kit::base::{GlobalState, POPUP_PRIORITY};
5use gpui_kit::base::{GlobalState, POPUP_PRIORITY};
6use gpui_kit::component::menu::PopupMenu;
6use gpui_kit::component::menu::PopupMenu;
7use gpui_kit::component::h_flex;
7use gpui_kit::component::h_flex;
8use gpui_kit::prelude::FluentBuilder as _;
8use gpui_kit::*;
9use gpui_kit::*;
9
10
10use super::message_actions::{MenuActions, MessageMenu, picker_button, reaction_button};
11use super::message_actions::{MenuActions, MessageMenu, picker_button, reaction_button};
@@ -32,6 +33,7 @@ pub struct OpenContextMenu {
32 pub serial: u64,
33 pub serial: u64,
33 popup: Rc<RefCell<Option<(Entity<PopupMenu>, Subscription)>>>,
34 popup: Rc<RefCell<Option<(Entity<PopupMenu>, Subscription)>>>,
34 bar_pressed: Rc<Cell<bool>>,
35 bar_pressed: Rc<Cell<bool>>,
36 list_height: Rc<Cell<Option<f32>>>,
35}
37}
36
38
37impl OpenContextMenu {
39impl OpenContextMenu {
@@ -42,6 +44,7 @@ impl OpenContextMenu {
42 serial,
44 serial,
43 popup: Rc::default(),
45 popup: Rc::default(),
44 bar_pressed: Rc::default(),
46 bar_pressed: Rc::default(),
47 list_height: Rc::default(),
45 }
48 }
46 }
49 }
47
50
@@ -65,6 +68,15 @@ impl OpenContextMenu {
65 }
68 }
66}
69}
67
70
71fn measure_height(height: Rc<Cell<Option<f32>>>) -> impl IntoElement {
72 canvas(
73 move |bounds, _, _| height.set(Some(f32::from(bounds.size.height))),
74 |_, _, _, _| {},
75 )
76 .absolute()
77 .size_full()
78}
79
68fn animated_reaction(button: AnyElement, index: usize, serial: u64) -> AnyElement {
80fn animated_reaction(button: AnyElement, index: usize, serial: u64) -> AnyElement {
69 let delay = REACTION_STAGGER * index as u32;
81 let delay = REACTION_STAGGER * index as u32;
70 let total = delay + REACTION_OPEN;
82 let total = delay + REACTION_OPEN;
@@ -83,7 +95,7 @@ fn animated_reaction(button: AnyElement, index: usize, serial: u64) -> AnyElemen
83 .into_any_element()
95 .into_any_element()
84}
96}
85
97
86/// Telegram's behaviour in our look: the menu opens at the cursor (flipped above it near the bottom edge), quick reactions sit on top of it.
98/// Telegram's behaviour in our look: reactions above the cursor, the menu below; near the bottom edge it turns upside down.
87pub fn message_context_menu(
99pub fn message_context_menu(
88 mut menu: MessageMenu,
100 mut menu: MessageMenu,
89 open: &OpenContextMenu,
101 open: &OpenContextMenu,
@@ -107,13 +119,24 @@ pub fn message_context_menu(
107 .map(|(index, glyph)| animated_reaction(reaction_button(&menu, glyph, index), index, serial))
119 .map(|(index, glyph)| animated_reaction(reaction_button(&menu, glyph, index), index, serial))
108 .collect();
120 .collect();
109 reactions.push(animated_reaction(picker_button(&menu, cx), menu.quick.len(), serial));
121 reactions.push(animated_reaction(picker_button(&menu, cx), menu.quick.len(), serial));
122 let viewport_height = f32::from(window.viewport_size().height);
123 let cursor_y = f32::from(open.position.y);
124 let upside_down = open
125 .list_height
126 .get()
127 .is_some_and(|height| cursor_y + height + WINDOW_MARGIN > viewport_height);
110 let bar_pressed = open.bar_pressed.clone();
128 let bar_pressed = open.bar_pressed.clone();
111 let bar = h_flex()
129 let bar = h_flex()
112 .debug_selector(|| format!("{CONTEXT_MENU_TAG}/reactions").into())
130 .debug_selector(|| format!("{CONTEXT_MENU_TAG}/reactions").into())
113 .absolute()
131 .absolute()
114 .left_0()
132 .left_0()
115 .bottom_full()
133 .map(|bar| {
116 .mb(px(PANEL_GAP))
134 if upside_down {
135 bar.top_full().mt(px(PANEL_GAP))
136 } else {
137 bar.bottom_full().mb(px(PANEL_GAP))
138 }
139 })
117 .occlude()
140 .occlude()
118 .on_scroll_wheel(|_, _, cx| cx.stop_propagation())
141 .on_scroll_wheel(|_, _, cx| cx.stop_propagation())
119 .h(px(TOOLBAR_HEIGHT))
142 .h(px(TOOLBAR_HEIGHT))
@@ -127,21 +150,28 @@ pub fn message_context_menu(
127 GlobalState::suppress_text_selection(cx);
150 GlobalState::suppress_text_selection(cx);
128 })
151 })
129 .children(reactions);
152 .children(reactions);
153 let slide = if upside_down { LIST_SLIDE } else { -LIST_SLIDE };
130 let list = div()
154 let list = div()
131 .relative()
155 .relative()
132 .debug_selector(|| format!("{CONTEXT_MENU_TAG}/list").into())
156 .debug_selector(|| format!("{CONTEXT_MENU_TAG}/list").into())
133 .child(popup)
157 .child(popup)
158 .child(measure_height(open.list_height.clone()))
134 .with_animation(
159 .with_animation(
135 ElementId::Name(format!("context-list-{serial}").into()),
160 ElementId::Name(format!("context-list-{serial}-{upside_down}").into()),
136 Animation::new(LIST_OPEN).with_easing(ease_out_quint()),
161 Animation::new(LIST_OPEN).with_easing(ease_out_quint()),
137 |element, delta| element.opacity(delta).top(px((delta - 1.) * LIST_SLIDE)),
162 move |element, delta| element.opacity(delta).top(px((1. - delta) * slide)),
138 );
163 );
139 let anchor_at = point(
164 let (anchor_at, corner) = if upside_down {
140 open.position.x,
165 let lowest = viewport_height - WINDOW_MARGIN - BAR_LIFT;
141 open.position.y.max(px(BAR_LIFT + WINDOW_MARGIN)),
166 (point(open.position.x, px(cursor_y.min(lowest))), Anchor::BottomLeft)
142 );
167 } else {
168 (
169 point(open.position.x, open.position.y.max(px(BAR_LIFT + WINDOW_MARGIN))),
170 Anchor::TopLeft,
171 )
172 };
143 deferred(
173 deferred(
144 anchored().position(anchor_at).child(
174 anchored().position(anchor_at).anchor(corner).child(
145 div()
175 div()
146 .id(ElementId::Name(format!("{CONTEXT_MENU_TAG}-{}", open.key).into()))
176 .id(ElementId::Name(format!("{CONTEXT_MENU_TAG}-{}", open.key).into()))
147 .debug_selector(|| CONTEXT_MENU_TAG.into())
177 .debug_selector(|| CONTEXT_MENU_TAG.into())