Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/coco-tui/src/components/code_highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ impl<'a> CodeHighlight<'a> {
}
}

/// Clears all overlays without rebuilding the widget from scratch.
/// The existing highlighted widget is preserved until the next async rebuild completes.
/// This prevents the visual flicker that would occur if we created a new placeholder widget.
pub fn clear_overlays(&mut self) {
if self.state.overlays.is_empty() {
return;
}
self.state.overlays.clear();
self.source_dirty = true;
if let Some(width) = self.last_width
&& self.pending_rx.is_none()
{
self.spawn_build(width);
}
}

fn build_placeholder_widget(source: &str, base_style: Option<Style>) -> Paragraph<'static> {
let base_style = base_style.unwrap_or_default();
let lines = source
Expand Down
10 changes: 9 additions & 1 deletion crates/coco-tui/src/components/messages/tool/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,15 @@ impl<'a> Bash<'a> {
*requiring_confirmation = value;
}
}
self.rebuild_input();
if value {
// Need to rebuild input to add overlays for unsafe ranges
self.rebuild_input();
} else {
// Just clear overlays without rebuilding the entire widget.
// This preserves the existing syntax highlighting and prevents
// the visual flicker that would occur if we created a new placeholder.
self.input.clear_overlays();
}
}

fn push_chunk(&mut self, chunk: OutputChunk) {
Expand Down