fix(chat): right-click menu flips above the cursor near the bottom edge
- Like Telegram: the list ends at the cursor when it does not fit below, reactions stay on top of the list - Also flips to the left near the right edge 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
ad9e785c0020a2b3a0d0fec0daecb138da003841- Parent
6bfef466
1 file changed
+23
−17
@@ -4,7 +4,7 @@ use std::time::Duration;
4
4
5
5
use gpui_kit::base::{GlobalState, POPUP_PRIORITY};
6
6
use gpui_kit::component::menu::PopupMenu;
7
use gpui_kit::component::{h_flex, v_flex};
7
use gpui_kit::component::h_flex;
8
8
use gpui_kit::*;
9
9
10
10
use super::message_actions::{MenuActions, MessageMenu, picker_button, reaction_button};
@@ -15,6 +15,7 @@ pub const CONTEXT_MENU_TAG: &str = "message-context-menu";
15
15
const PANEL_GAP: f32 = 6.;
16
16
const BAR_PADDING: f32 = 3.;
17
17
const WINDOW_MARGIN: f32 = 8.;
18
const BAR_LIFT: f32 = TOOLBAR_HEIGHT + PANEL_GAP;
18
19
const LIST_OPEN: Duration = Duration::from_millis(160);
19
20
const REACTION_OPEN: Duration = Duration::from_millis(140);
20
21
const REACTION_STAGGER: Duration = Duration::from_millis(35);
@@ -82,7 +83,7 @@ fn animated_reaction(button: AnyElement, index: usize, serial: u64) -> AnyElemen
82
83
.into_any_element()
83
84
}
84
85
85
/// Telegram's behaviour in our look: quick reactions right above the cursor, the message menu right below it.
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.
86
87
pub fn message_context_menu(
87
88
mut menu: MessageMenu,
88
89
open: &OpenContextMenu,
@@ -109,6 +110,12 @@ pub fn message_context_menu(
109
110
let bar_pressed = open.bar_pressed.clone();
110
111
let bar = h_flex()
111
112
.debug_selector(|| format!("{CONTEXT_MENU_TAG}/reactions").into())
113
.absolute()
114
.left_0()
115
.bottom_full()
116
.mb(px(PANEL_GAP))
117
.occlude()
118
.on_scroll_wheel(|_, _, cx| cx.stop_propagation())
112
119
.h(px(TOOLBAR_HEIGHT))
113
120
.px(px(BAR_PADDING))
114
121
.gap(px(1.))
@@ -129,22 +136,21 @@ pub fn message_context_menu(
129
136
Animation::new(LIST_OPEN).with_easing(ease_out_quint()),
130
137
|element, delta| element.opacity(delta).top(px((delta - 1.) * LIST_SLIDE)),
131
138
);
132
let lifted = open.position - point(px(0.), px(TOOLBAR_HEIGHT + PANEL_GAP));
139
let anchor_at = point(
140
open.position.x,
141
open.position.y.max(px(BAR_LIFT + WINDOW_MARGIN)),
142
);
133
143
deferred(
134
anchored()
135
.position(lifted)
136
.snap_to_window_with_margin(px(WINDOW_MARGIN))
137
.child(
138
v_flex()
139
.id(ElementId::Name(format!("{CONTEXT_MENU_TAG}-{}", open.key).into()))
140
.debug_selector(|| CONTEXT_MENU_TAG.into())
141
.items_start()
142
.gap(px(PANEL_GAP))
143
.occlude()
144
.on_scroll_wheel(|_, _, cx| cx.stop_propagation())
145
.child(bar)
146
.child(list),
147
),
144
anchored().position(anchor_at).child(
145
div()
146
.id(ElementId::Name(format!("{CONTEXT_MENU_TAG}-{}", open.key).into()))
147
.debug_selector(|| CONTEXT_MENU_TAG.into())
148
.relative()
149
.occlude()
150
.on_scroll_wheel(|_, _, cx| cx.stop_propagation())
151
.child(list)
152
.child(bar),
153
),
148
154
)
149
155
.with_priority(POPUP_PRIORITY)
150
156
.into_any_element()
@@ -4,7 +4,7 @@ use std::time::Duration;4
4
5
use gpui_kit::base::{GlobalState, POPUP_PRIORITY};5
use gpui_kit::base::{GlobalState, POPUP_PRIORITY};6
use gpui_kit::component::menu::PopupMenu;6
use gpui_kit::component::menu::PopupMenu;7
use gpui_kit::component::{h_flex, v_flex};7
use gpui_kit::component::h_flex;8
use gpui_kit::*;8
use gpui_kit::*;9
9
10
use super::message_actions::{MenuActions, MessageMenu, picker_button, reaction_button};10
use super::message_actions::{MenuActions, MessageMenu, picker_button, reaction_button};@@ -15,6 +15,7 @@ pub const CONTEXT_MENU_TAG: &str = "message-context-menu";15
const PANEL_GAP: f32 = 6.;15
const PANEL_GAP: f32 = 6.;16
const BAR_PADDING: f32 = 3.;16
const BAR_PADDING: f32 = 3.;17
const WINDOW_MARGIN: f32 = 8.;17
const WINDOW_MARGIN: f32 = 8.;18
const BAR_LIFT: f32 = TOOLBAR_HEIGHT + PANEL_GAP;18
const LIST_OPEN: Duration = Duration::from_millis(160);19
const LIST_OPEN: Duration = Duration::from_millis(160);19
const REACTION_OPEN: Duration = Duration::from_millis(140);20
const REACTION_OPEN: Duration = Duration::from_millis(140);20
const REACTION_STAGGER: Duration = Duration::from_millis(35);21
const REACTION_STAGGER: Duration = Duration::from_millis(35);@@ -82,7 +83,7 @@ fn animated_reaction(button: AnyElement, index: usize, serial: u64) -> AnyElemen82
.into_any_element()83
.into_any_element()83
}84
}84
85
85
/// Telegram's behaviour in our look: quick reactions right above the cursor, the message menu right below it.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.86
pub fn message_context_menu(87
pub fn message_context_menu(87
mut menu: MessageMenu,88
mut menu: MessageMenu,88
open: &OpenContextMenu,89
open: &OpenContextMenu,@@ -109,6 +110,12 @@ pub fn message_context_menu(109
let bar_pressed = open.bar_pressed.clone();110
let bar_pressed = open.bar_pressed.clone();110
let bar = h_flex()111
let bar = h_flex()111
.debug_selector(|| format!("{CONTEXT_MENU_TAG}/reactions").into())112
.debug_selector(|| format!("{CONTEXT_MENU_TAG}/reactions").into())113
.absolute()114
.left_0()115
.bottom_full()116
.mb(px(PANEL_GAP))117
.occlude()118
.on_scroll_wheel(|_, _, cx| cx.stop_propagation())112
.h(px(TOOLBAR_HEIGHT))119
.h(px(TOOLBAR_HEIGHT))113
.px(px(BAR_PADDING))120
.px(px(BAR_PADDING))114
.gap(px(1.))121
.gap(px(1.))@@ -129,22 +136,21 @@ pub fn message_context_menu(129
Animation::new(LIST_OPEN).with_easing(ease_out_quint()),136
Animation::new(LIST_OPEN).with_easing(ease_out_quint()),130
|element, delta| element.opacity(delta).top(px((delta - 1.) * LIST_SLIDE)),137
|element, delta| element.opacity(delta).top(px((delta - 1.) * LIST_SLIDE)),131
);138
);132
let lifted = open.position - point(px(0.), px(TOOLBAR_HEIGHT + PANEL_GAP));139
let anchor_at = point(140
open.position.x,141
open.position.y.max(px(BAR_LIFT + WINDOW_MARGIN)),142
);133
deferred(143
deferred(134
anchored()144
anchored().position(anchor_at).child(135
.position(lifted)145
div()136
.snap_to_window_with_margin(px(WINDOW_MARGIN))146
.id(ElementId::Name(format!("{CONTEXT_MENU_TAG}-{}", open.key).into()))137
.child(147
.debug_selector(|| CONTEXT_MENU_TAG.into())138
v_flex()148
.relative()139
.id(ElementId::Name(format!("{CONTEXT_MENU_TAG}-{}", open.key).into()))149
.occlude()140
.debug_selector(|| CONTEXT_MENU_TAG.into())150
.on_scroll_wheel(|_, _, cx| cx.stop_propagation())141
.items_start()151
.child(list)142
.gap(px(PANEL_GAP))152
.child(bar),143
.occlude()153
),144
.on_scroll_wheel(|_, _, cx| cx.stop_propagation())145
.child(bar)146
.child(list),147
),148
)154
)149
.with_priority(POPUP_PRIORITY)155
.with_priority(POPUP_PRIORITY)150
.into_any_element()156
.into_any_element()