Skip to content

Commit c965e66

Browse files
committed
fix(tui): fix mention popup positioning and Unicode width calculation
1 parent 609ab01 commit c965e66

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/cortex-tui/src/widgets/mention_popup.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ impl<'a> MentionPopup<'a> {
8585
let item_count = self.state.visible_results().len() as u16;
8686
let height = (item_count + 2).min(MAX_HEIGHT + 2); // +2 for borders
8787

88-
// Calculate width based on content
88+
// Calculate width based on content (use chars().count() for Unicode support)
8989
let content_width = self
9090
.state
9191
.results()
9292
.iter()
93-
.map(|p| p.to_string_lossy().len())
93+
.map(|p| p.to_string_lossy().chars().count())
9494
.max()
9595
.unwrap_or(20) as u16;
9696

@@ -195,8 +195,11 @@ impl Widget for MentionPopup<'_> {
195195

196196
let (width, height) = self.calculate_dimensions(area);
197197

198-
// Position the popup
199-
let popup_area = if self.above {
198+
// Position the popup - check if it fits above, otherwise render below
199+
let fits_above = area.y >= height;
200+
let render_above = self.above && fits_above;
201+
202+
let popup_area = if render_above {
200203
Rect::new(area.x, area.y.saturating_sub(height), width, height)
201204
} else {
202205
Rect::new(

0 commit comments

Comments
 (0)