diff --git a/client/Cargo.toml b/client/Cargo.toml index 9f14786..e09ac46 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -19,3 +19,4 @@ tokio = { version = "1.43.0", features = ["full", "macros"] } toml = "0.8.20" tonic = "0.12.3" tracing = "0.1.41" +unicode-width = "0.2.0" diff --git a/client/src/components/common/autocomplete.rs b/client/src/components/common/autocomplete.rs index 1c2cd2f..5d3c23d 100644 --- a/client/src/components/common/autocomplete.rs +++ b/client/src/components/common/autocomplete.rs @@ -7,6 +7,7 @@ use ratatui::{ widgets::{Block, List, ListItem, ListState}, Frame, }; +use unicode_width::UnicodeWidthStr; /// Renders an opaque dropdown list for autocomplete suggestions. pub fn render_autocomplete_dropdown( @@ -21,10 +22,10 @@ pub fn render_autocomplete_dropdown( return; } // --- Calculate Dropdown Size & Position --- - let max_suggestion_width = suggestions.iter().map(|s| s.len()).max().unwrap_or(0) as u16; - // Ensure dropdown is at least as wide as the input field, or the longest suggestion, min 10 - let dropdown_width = max_suggestion_width.max(input_rect.width).max(10); - let dropdown_height = (suggestions.len() as u16).min(5); // Max 5 suggestions visible + let max_suggestion_width = suggestions.iter().map(|s| s.width()).max().unwrap_or(0) as u16; + let horizontal_padding: u16 = 2; + let dropdown_width = (max_suggestion_width + horizontal_padding).max(10); + let dropdown_height = (suggestions.len() as u16).min(5); let mut dropdown_area = Rect { x: input_rect.x, // Align horizontally with input