From dacea1e99d92e4ff5a8930f0783199203c7bd4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E7=8E=AE=20=28Jade=20Lin=29?= Date: Thu, 22 Jan 2026 13:23:59 +0800 Subject: [PATCH] fix(bash): prevent visual flicker when toggling confirmation mode - Add clear_overlays method to CodeHighlight to remove overlays without rebuilding - Use clear_overlays instead of rebuild_input when disabling confirmation - Preserves existing syntax highlighting and prevents visual flicker --- crates/coco-tui/src/components/code_highlight.rs | 16 ++++++++++++++++ .../src/components/messages/tool/bash.rs | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/coco-tui/src/components/code_highlight.rs b/crates/coco-tui/src/components/code_highlight.rs index 8ac0843..4eca38b 100644 --- a/crates/coco-tui/src/components/code_highlight.rs +++ b/crates/coco-tui/src/components/code_highlight.rs @@ -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