width for the dropdown fixed

This commit is contained in:
filipriec
2025-04-12 17:41:37 +02:00
parent b4053a7b94
commit d4d5bcec9e
2 changed files with 6 additions and 4 deletions

View File

@@ -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"

View File

@@ -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