BlueGit

ict rusty-teams

fix(composer): mention suggestions stay inside the window

- Anchored at the @ like the emoji popup, rendered deferred so no parent clips it
- Opens below the line when there is no room above (new post at the top of a channel)

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
9b45785d547940fe6d3fe76d931766003f9174d4
Parent
6c58b9ba
1 file changed +47 −15
crates/app/src/views/composer.rs +47 −15
@@ -23,6 +23,7 @@ use gpui_kit::component::{
23 23 };
24 24 use gpui_kit::prelude::FluentBuilder as _;
25 25 use gpui_kit::*;
26 use crate::views::title_bar::TITLE_BAR_HEIGHT;
26 27 use teams_core::{
27 28 Draft, DraftLine, Edit, EnterKeyBehavior, FileReference, FormatState, LineKind, LinkPreview,
28 29 MarkKind, MentionCandidate, MentionInput, OBJECT_MARK, SizeStep, TABLE_MARK, TableEdit,
@@ -91,6 +92,9 @@ const MENTION_QUERY_MAX_CHARS: usize = 32;
91 92 const MENTION_QUERY_MAX_WORDS: usize = 3;
92 93 const POPUP_WIDTH: f32 = 380.;
93 94 const POPUP_ROW_HEIGHT: f32 = 44.;
95 const POPUP_PADDING: f32 = 6.;
96 const POPUP_GAP: f32 = 6.;
97 pub const MENTION_POPUP_TAG: &str = "composer/mention-popup";
94 98 const DEMO_UPLOAD_STEPS: u8 = 10;
95 99 const COMPOSER_PLACEHOLDER: &str = "Type a message";
96 100 const SEND_DIVIDER_HEIGHT: f32 = 20.;
@@ -2501,11 +2505,17 @@ impl Composer {
2501 2505 self.input.update(cx, |state, cx| state.focus(window, cx));
2502 2506 }
2503 2507
2504 fn render_popup(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
2508 fn render_popup(&self, window: &mut Window, cx: &mut Context<Self>) -> Option<AnyElement> {
2505 2509 let popup = self
2506 2510 .popup
2507 2511 .as_ref()
2508 2512 .filter(|popup| !popup.candidates.is_empty())?;
2513 let at_sign = popup.range.start..popup.range.start + 1;
2514 let anchor = self.input.read(cx).range_to_bounds(&at_sign);
2515 if anchor.is_none() {
2516 window.request_animation_frame();
2517 }
2518 let popup_height = popup.candidates.len() as f32 * POPUP_ROW_HEIGHT + 2. * POPUP_PADDING;
2509 2519 let directory = &self.app.read(cx).directory;
2510 2520 let rows = popup
2511 2521 .candidates
@@ -2558,20 +2568,42 @@ impl Composer {
2558 2568 this.accept_mention(window, cx);
2559 2569 }))
2560 2570 });
2571 let panel = v_flex()
2572 .id("mention-popup")
2573 .debug_selector(|| MENTION_POPUP_TAG.into())
2574 .w(px(POPUP_WIDTH))
2575 .py(px(POPUP_PADDING))
2576 .rounded(px(10.))
2577 .flyout_surface()
2578 .occlude()
2579 .children(rows);
2580 let Some(anchor) = anchor else {
2581 return Some(
2582 div()
2583 .absolute()
2584 .bottom(relative(1.))
2585 .left_0()
2586 .mb(px(POPUP_GAP))
2587 .child(panel)
2588 .into_any_element(),
2589 );
2590 };
2591 let room_above = f32::from(anchor.top()) - POPUP_GAP - TITLE_BAR_HEIGHT;
2592 let (position, corner) = if room_above >= popup_height {
2593 (point(anchor.left(), anchor.top() - px(POPUP_GAP)), Anchor::BottomLeft)
2594 } else {
2595 (point(anchor.left(), anchor.bottom() + px(POPUP_GAP)), Anchor::TopLeft)
2596 };
2561 2597 Some(
2562 v_flex()
2563 .id("mention-popup")
2564 .absolute()
2565 .bottom(relative(1.))
2566 .left_0()
2567 .mb(px(6.))
2568 .w(px(POPUP_WIDTH))
2569 .py(px(6.))
2570 .rounded(px(10.))
2571 .flyout_surface()
2572 .occlude()
2573 .children(rows)
2574 .into_any_element(),
2598 deferred(
2599 anchored()
2600 .position(position)
2601 .anchor(corner)
2602 .snap_to_window_with_margin(px(POPUP_GAP))
2603 .child(panel),
2604 )
2605 .with_priority(1)
2606 .into_any_element(),
2575 2607 )
2576 2608 }
2577 2609
@@ -3459,7 +3491,7 @@ impl Render for Composer {
3459 3491 div()
3460 3492 .relative()
3461 3493 .w_full()
3462 .children(self.render_popup(cx))
3494 .children(self.render_popup(window, cx))
3463 3495 .children(self.render_slash_popup(cx))
3464 3496 .children(self.render_emoji_popup(window, cx))
3465 3497 .children(self.render_toolbar(focused, cx))
@@ -23,6 +23,7 @@ use gpui_kit::component::{
23};
23};
24use gpui_kit::prelude::FluentBuilder as _;
24use gpui_kit::prelude::FluentBuilder as _;
25use gpui_kit::*;
25use gpui_kit::*;
26use crate::views::title_bar::TITLE_BAR_HEIGHT;
26use teams_core::{
27use teams_core::{
27 Draft, DraftLine, Edit, EnterKeyBehavior, FileReference, FormatState, LineKind, LinkPreview,
28 Draft, DraftLine, Edit, EnterKeyBehavior, FileReference, FormatState, LineKind, LinkPreview,
28 MarkKind, MentionCandidate, MentionInput, OBJECT_MARK, SizeStep, TABLE_MARK, TableEdit,
29 MarkKind, MentionCandidate, MentionInput, OBJECT_MARK, SizeStep, TABLE_MARK, TableEdit,
@@ -91,6 +92,9 @@ const MENTION_QUERY_MAX_CHARS: usize = 32;
91const MENTION_QUERY_MAX_WORDS: usize = 3;
92const MENTION_QUERY_MAX_WORDS: usize = 3;
92const POPUP_WIDTH: f32 = 380.;
93const POPUP_WIDTH: f32 = 380.;
93const POPUP_ROW_HEIGHT: f32 = 44.;
94const POPUP_ROW_HEIGHT: f32 = 44.;
95const POPUP_PADDING: f32 = 6.;
96const POPUP_GAP: f32 = 6.;
97pub const MENTION_POPUP_TAG: &str = "composer/mention-popup";
94const DEMO_UPLOAD_STEPS: u8 = 10;
98const DEMO_UPLOAD_STEPS: u8 = 10;
95const COMPOSER_PLACEHOLDER: &str = "Type a message";
99const COMPOSER_PLACEHOLDER: &str = "Type a message";
96const SEND_DIVIDER_HEIGHT: f32 = 20.;
100const SEND_DIVIDER_HEIGHT: f32 = 20.;
@@ -2501,11 +2505,17 @@ impl Composer {
2501 self.input.update(cx, |state, cx| state.focus(window, cx));
2505 self.input.update(cx, |state, cx| state.focus(window, cx));
2502 }
2506 }
2503
2507
2504 fn render_popup(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
2508 fn render_popup(&self, window: &mut Window, cx: &mut Context<Self>) -> Option<AnyElement> {
2505 let popup = self
2509 let popup = self
2506 .popup
2510 .popup
2507 .as_ref()
2511 .as_ref()
2508 .filter(|popup| !popup.candidates.is_empty())?;
2512 .filter(|popup| !popup.candidates.is_empty())?;
2513 let at_sign = popup.range.start..popup.range.start + 1;
2514 let anchor = self.input.read(cx).range_to_bounds(&at_sign);
2515 if anchor.is_none() {
2516 window.request_animation_frame();
2517 }
2518 let popup_height = popup.candidates.len() as f32 * POPUP_ROW_HEIGHT + 2. * POPUP_PADDING;
2509 let directory = &self.app.read(cx).directory;
2519 let directory = &self.app.read(cx).directory;
2510 let rows = popup
2520 let rows = popup
2511 .candidates
2521 .candidates
@@ -2558,20 +2568,42 @@ impl Composer {
2558 this.accept_mention(window, cx);
2568 this.accept_mention(window, cx);
2559 }))
2569 }))
2560 });
2570 });
2571 let panel = v_flex()
2572 .id("mention-popup")
2573 .debug_selector(|| MENTION_POPUP_TAG.into())
2574 .w(px(POPUP_WIDTH))
2575 .py(px(POPUP_PADDING))
2576 .rounded(px(10.))
2577 .flyout_surface()
2578 .occlude()
2579 .children(rows);
2580 let Some(anchor) = anchor else {
2581 return Some(
2582 div()
2583 .absolute()
2584 .bottom(relative(1.))
2585 .left_0()
2586 .mb(px(POPUP_GAP))
2587 .child(panel)
2588 .into_any_element(),
2589 );
2590 };
2591 let room_above = f32::from(anchor.top()) - POPUP_GAP - TITLE_BAR_HEIGHT;
2592 let (position, corner) = if room_above >= popup_height {
2593 (point(anchor.left(), anchor.top() - px(POPUP_GAP)), Anchor::BottomLeft)
2594 } else {
2595 (point(anchor.left(), anchor.bottom() + px(POPUP_GAP)), Anchor::TopLeft)
2596 };
2561 Some(
2597 Some(
2562 v_flex()
2598 deferred(
2563 .id("mention-popup")
2599 anchored()
2564 .absolute()
2600 .position(position)
2565 .bottom(relative(1.))
2601 .anchor(corner)
2566 .left_0()
2602 .snap_to_window_with_margin(px(POPUP_GAP))
2567 .mb(px(6.))
2603 .child(panel),
2568 .w(px(POPUP_WIDTH))
2604 )
2569 .py(px(6.))
2605 .with_priority(1)
2570 .rounded(px(10.))
2606 .into_any_element(),
2571 .flyout_surface()
2572 .occlude()
2573 .children(rows)
2574 .into_any_element(),
2575 )
2607 )
2576 }
2608 }
2577
2609
@@ -3459,7 +3491,7 @@ impl Render for Composer {
3459 div()
3491 div()
3460 .relative()
3492 .relative()
3461 .w_full()
3493 .w_full()
3462 .children(self.render_popup(cx))
3494 .children(self.render_popup(window, cx))
3463 .children(self.render_slash_popup(cx))
3495 .children(self.render_slash_popup(cx))
3464 .children(self.render_emoji_popup(window, cx))
3496 .children(self.render_emoji_popup(window, cx))
3465 .children(self.render_toolbar(focused, cx))
3497 .children(self.render_toolbar(focused, cx))