Refactor: simplify word navigation logic, improve line wrapping, and enhance parameter initialization across core and TUI modules.

This commit is contained in:
2025-09-30 02:54:07 +02:00
parent 8ee4c5f384
commit 053f389b1e
6 changed files with 27 additions and 45 deletions

View File

@@ -1320,8 +1320,10 @@ impl ChatApp {
self.status = format!("Loading model '{}'...", self.controller.selected_model());
self.start_loading_animation();
let mut parameters = ChatParameters::default();
parameters.stream = self.controller.config().general.enable_streaming;
let parameters = ChatParameters {
stream: self.controller.config().general.enable_streaming,
..Default::default()
};
// Step 2: Start the actual request
match self
@@ -1392,7 +1394,7 @@ impl ChatApp {
} else {
// If the current model is not in the filtered list, select the first one
self.selected_model = Some(0);
if let Some(model) = filtered_models.get(0) {
if let Some(model) = filtered_models.first() {
self.controller.set_model(model.id.clone());
// Also update the config with the new model and provider
self.controller.config_mut().general.default_model = Some(model.id.clone());

View File

@@ -30,7 +30,7 @@ pub fn render_chat(frame: &mut Frame<'_>, app: &mut ChatApp) {
} else {
buffer_text.lines().collect()
};
let visual_lines = calculate_wrapped_line_count(lines.into_iter(), available_width);
let visual_lines = calculate_wrapped_line_count(lines, available_width);
(visual_lines as u16).min(10) + 2 // +2 for borders
};
@@ -283,7 +283,7 @@ fn compute_cursor_metrics(
for (row_idx, line) in lines.iter().enumerate() {
let display_owned = mask_char.map(|mask| mask_line(line, mask));
let display_line = display_owned.as_deref().unwrap_or_else(|| line.as_str());
let display_line = display_owned.as_deref().unwrap_or(line.as_str());
let mut segments = if wrap_lines {
wrap_line_segments(display_line, content_width)
@@ -889,7 +889,7 @@ fn render_input(frame: &mut Frame<'_>, area: Rect, app: &mut ChatApp) {
let lines: Vec<Line> = if input_text.is_empty() {
vec![Line::from("Press 'i' to start typing")]
} else {
input_text.lines().map(|line| Line::from(line)).collect()
input_text.lines().map(Line::from).collect()
};
let paragraph = Paragraph::new(lines)