insert history lines with redraw (#1769)
This delays the call to insert_history_lines until a redraw is happening. Crucially, the new lines are inserted _after the viewport is resized_. This results in fewer stray blank lines below the viewport when modals (e.g. user approval) are closed.
This commit is contained in:
@@ -17,6 +17,7 @@ use crossterm::event::KeyEvent;
|
|||||||
use crossterm::event::KeyEventKind;
|
use crossterm::event::KeyEventKind;
|
||||||
use ratatui::layout::Offset;
|
use ratatui::layout::Offset;
|
||||||
use ratatui::prelude::Backend;
|
use ratatui::prelude::Backend;
|
||||||
|
use ratatui::text::Line;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
@@ -55,6 +56,8 @@ pub(crate) struct App<'a> {
|
|||||||
/// True when a redraw has been scheduled but not yet executed.
|
/// True when a redraw has been scheduled but not yet executed.
|
||||||
pending_redraw: Arc<AtomicBool>,
|
pending_redraw: Arc<AtomicBool>,
|
||||||
|
|
||||||
|
pending_history_lines: Vec<Line<'static>>,
|
||||||
|
|
||||||
/// Stored parameters needed to instantiate the ChatWidget later, e.g.,
|
/// Stored parameters needed to instantiate the ChatWidget later, e.g.,
|
||||||
/// after dismissing the Git-repo warning.
|
/// after dismissing the Git-repo warning.
|
||||||
chat_args: Option<ChatWidgetArgs>,
|
chat_args: Option<ChatWidgetArgs>,
|
||||||
@@ -152,6 +155,7 @@ impl App<'_> {
|
|||||||
let file_search = FileSearchManager::new(config.cwd.clone(), app_event_tx.clone());
|
let file_search = FileSearchManager::new(config.cwd.clone(), app_event_tx.clone());
|
||||||
Self {
|
Self {
|
||||||
app_event_tx,
|
app_event_tx,
|
||||||
|
pending_history_lines: Vec::new(),
|
||||||
app_event_rx,
|
app_event_rx,
|
||||||
app_state,
|
app_state,
|
||||||
config,
|
config,
|
||||||
@@ -197,7 +201,7 @@ impl App<'_> {
|
|||||||
while let Ok(event) = self.app_event_rx.recv() {
|
while let Ok(event) = self.app_event_rx.recv() {
|
||||||
match event {
|
match event {
|
||||||
AppEvent::InsertHistory(lines) => {
|
AppEvent::InsertHistory(lines) => {
|
||||||
crate::insert_history::insert_history_lines(terminal, lines);
|
self.pending_history_lines.extend(lines);
|
||||||
self.app_event_tx.send(AppEvent::RequestRedraw);
|
self.app_event_tx.send(AppEvent::RequestRedraw);
|
||||||
}
|
}
|
||||||
AppEvent::RequestRedraw => {
|
AppEvent::RequestRedraw => {
|
||||||
@@ -409,6 +413,13 @@ impl App<'_> {
|
|||||||
terminal.clear()?;
|
terminal.clear()?;
|
||||||
terminal.set_viewport_area(area);
|
terminal.set_viewport_area(area);
|
||||||
}
|
}
|
||||||
|
if !self.pending_history_lines.is_empty() {
|
||||||
|
crate::insert_history::insert_history_lines(
|
||||||
|
terminal,
|
||||||
|
self.pending_history_lines.clone(),
|
||||||
|
);
|
||||||
|
self.pending_history_lines.clear();
|
||||||
|
}
|
||||||
match &mut self.app_state {
|
match &mut self.app_state {
|
||||||
AppState::Chat { widget } => {
|
AppState::Chat { widget } => {
|
||||||
terminal.draw(|frame| frame.render_widget_ref(&**widget, frame.area()))?;
|
terminal.draw(|frame| frame.render_widget_ref(&**widget, frame.area()))?;
|
||||||
|
|||||||
Reference in New Issue
Block a user