refactor(realtime): trim diff by reusing transcription placeholders

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Ahmed Ibrahim
2026-02-23 16:48:21 -08:00
co-authored by Codex
parent f7c740fff1
commit 5f8024e9e4
4 changed files with 26 additions and 62 deletions
+1 -3
View File
@@ -2719,9 +2719,7 @@ impl App {
}
AppEvent::UpdateRecordingMeter { id, text } => {
// Update in place to preserve the element id for subsequent frames.
let updated = self
.chat_widget
.update_named_placeholder_in_place(&id, &text);
let updated = self.chat_widget.update_transcription_in_place(&id, &text);
if updated {
tui.frame_requester().schedule_frame();
}
+4 -12
View File
@@ -1009,18 +1009,6 @@ impl ChatComposer {
self.sync_popups();
}
pub(crate) fn insert_named_placeholder(&mut self, id: &str, text: &str) {
self.textarea.insert_named_element(text, id.to_string());
}
pub(crate) fn update_named_placeholder_in_place(&mut self, id: &str, text: &str) -> bool {
self.textarea.update_named_element_by_id(id, text)
}
pub(crate) fn remove_named_placeholder(&mut self, id: &str) {
let _ = self.textarea.replace_element_by_id(id, "");
}
pub(crate) fn clear_for_ctrl_c(&mut self) -> Option<String> {
if self.is_empty() {
return None;
@@ -3956,6 +3944,10 @@ impl ChatComposer {
let _ = self.textarea.replace_element_by_id(id, text);
}
pub fn update_transcription_in_place(&mut self, id: &str, text: &str) -> bool {
self.textarea.update_named_element_by_id(id, text)
}
pub fn remove_transcription_placeholder(&mut self, id: &str) {
self.stop_transcription_spinner(id);
let _ = self.textarea.replace_element_by_id(id, "");
+11 -27
View File
@@ -14,9 +14,6 @@
//! Some UI is time-based rather than input-based, such as the transient "press again to quit"
//! hint. The pane schedules redraws so those hints can expire even when the UI is otherwise idle.
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::AtomicU16;
use crate::app_event::ConnectorsSnapshot;
use crate::app_event_sender::AppEventSender;
@@ -569,33 +566,12 @@ impl BottomPane {
self.request_redraw();
}
pub(crate) fn insert_named_placeholder(&mut self, id: &str, text: &str) {
self.composer.insert_named_placeholder(id, text);
self.composer.sync_popups();
self.request_redraw();
}
pub(crate) fn update_named_placeholder_in_place(&mut self, id: &str, text: &str) -> bool {
let updated = self.composer.update_named_placeholder_in_place(id, text);
if updated {
self.composer.sync_popups();
self.request_redraw();
}
updated
}
pub(crate) fn remove_named_placeholder(&mut self, id: &str) {
self.composer.remove_named_placeholder(id);
self.composer.sync_popups();
self.request_redraw();
}
pub(crate) fn spawn_live_meter_updates(
&self,
id: String,
prefix: Option<String>,
last_peak: Arc<AtomicU16>,
stop: Arc<AtomicBool>,
last_peak: std::sync::Arc<std::sync::atomic::AtomicU16>,
stop: std::sync::Arc<std::sync::atomic::AtomicBool>,
) {
self.composer
.spawn_live_meter_updates(id, prefix, last_peak, stop);
@@ -1043,7 +1019,6 @@ impl BottomPane {
}
}
#[cfg(not(target_os = "linux"))]
impl BottomPane {
pub(crate) fn replace_transcription(&mut self, id: &str, text: &str) {
self.composer.replace_transcription(id, text);
@@ -1051,6 +1026,15 @@ impl BottomPane {
self.request_redraw();
}
pub(crate) fn update_transcription_in_place(&mut self, id: &str, text: &str) -> bool {
let updated = self.composer.update_transcription_in_place(id, text);
if updated {
self.composer.sync_popups();
self.request_redraw();
}
updated
}
pub(crate) fn remove_transcription_placeholder(&mut self, id: &str) {
self.composer.remove_transcription_placeholder(id);
self.composer.sync_popups();
+10 -20
View File
@@ -3436,23 +3436,6 @@ impl ChatWidget {
self.bottom_pane.set_footer_hint_override(items);
}
pub(crate) fn insert_named_placeholder(&mut self, id: &str, text: &str) {
self.bottom_pane.insert_named_placeholder(id, text);
}
pub(crate) fn update_named_placeholder_in_place(&mut self, id: &str, text: &str) -> bool {
let updated = self.bottom_pane.update_named_placeholder_in_place(id, text);
if updated {
self.request_redraw();
}
updated
}
pub(crate) fn remove_named_placeholder(&mut self, id: &str) {
self.bottom_pane.remove_named_placeholder(id);
self.request_redraw();
}
pub(crate) fn show_selection_view(&mut self, params: SelectionViewParams) {
self.bottom_pane.show_selection_view(params);
self.request_redraw();
@@ -3469,7 +3452,7 @@ impl ChatWidget {
"Stop voice chat".to_string(),
)]));
let id = REALTIME_METER_PLACEHOLDER_ID.to_string();
self.insert_named_placeholder(&id, "Realtime listening ⠤⠤⠤⠤");
self.replace_transcription(&id, "Realtime listening ⠤⠤⠤⠤");
if let Some(controller) = &self.realtime_audio_controller
&& let Some(RealtimeMicMeterHandles { last_peak, stop }) = controller.meter_handles()
@@ -3488,7 +3471,7 @@ impl ChatWidget {
fn disable_realtime_ui(&mut self) {
self.set_footer_hint_override(None);
if let Some(id) = self.realtime_meter_placeholder_id.take() {
self.remove_named_placeholder(&id);
self.remove_transcription_placeholder(&id);
}
}
@@ -7771,7 +7754,6 @@ impl ChatWidget {
}
}
#[cfg(not(target_os = "linux"))]
impl ChatWidget {
pub(crate) fn replace_transcription(&mut self, id: &str, text: &str) {
self.bottom_pane.replace_transcription(id, text);
@@ -7779,6 +7761,14 @@ impl ChatWidget {
self.request_redraw();
}
pub(crate) fn update_transcription_in_place(&mut self, id: &str, text: &str) -> bool {
let updated = self.bottom_pane.update_transcription_in_place(id, text);
if updated {
self.request_redraw();
}
updated
}
pub(crate) fn remove_transcription_placeholder(&mut self, id: &str) {
self.bottom_pane.remove_transcription_placeholder(id);
// Ensure the UI redraws to reflect placeholder removal.