diff --git a/codex-rs/tui/src/app.rs b/codex-rs/tui/src/app.rs index 55b7892751..a59c4a5e2e 100644 --- a/codex-rs/tui/src/app.rs +++ b/codex-rs/tui/src/app.rs @@ -1036,9 +1036,9 @@ impl App { return Ok(AppRunControl::Continue); } let transcript_owns_input = match (&event, &self.overlay) { - (TuiEvent::Key(key), Some(Overlay::Transcript(overlay))) => { - overlay.owns_interaction_key(*key) - } + (TuiEvent::Key(key), Some(overlay)) => overlay + .input_transcript() + .is_some_and(|view| view.owns_interaction_key(*key)), (TuiEvent::Key(key), None) => { tui.is_owned_screen() && self.chat_widget.no_modal_or_popup_active() diff --git a/codex-rs/tui/src/app/input.rs b/codex-rs/tui/src/app/input.rs index 39fc93b078..2dd5e699dd 100644 --- a/codex-rs/tui/src/app/input.rs +++ b/codex-rs/tui/src/app/input.rs @@ -94,7 +94,7 @@ impl App { self.chat_widget .observe_config_editor_transition_key_event(key_event); self.transcript_view.set_keymap_bindings(&self.keymap); - if let Some(Overlay::Transcript(overlay)) = &mut self.overlay { + if let Some(overlay) = &mut self.overlay { overlay.set_keymap_bindings(&self.keymap); } if self.overlay.is_none() && self.chat_widget.handle_quick_dial_menu(key_event) { @@ -102,7 +102,11 @@ impl App { } let contexts = self.key_chord_contexts(tui); let select_mode_chord = self.select_mode_owns_chord(tui, key_event); - if (matches!(&self.overlay, Some(Overlay::Transcript(overlay)) if overlay.owns_interaction_key(key_event)) + if (self + .overlay + .as_ref() + .and_then(Overlay::input_transcript) + .is_some_and(|view| view.owns_interaction_key(key_event)) || (tui.is_owned_screen() && self.overlay.is_none() && !self.focused_sidebar_chooser(tui) @@ -285,16 +289,16 @@ impl App { use crate::keymap::KeymapContextSet; if let Some(overlay) = &self.overlay { - let contexts = match overlay { - Overlay::Transcript(view) if view.is_search_editing() => { + let contexts = match overlay.input_transcript() { + Some(view) if view.is_search_editing() => { KeymapContextSet::new(KeymapContext::Editor) } - Overlay::Transcript(view) if view.is_select_mode() => { + Some(view) if view.is_select_mode() => { KeymapContextSet::transcript().with_transcript_select() } _ if self.backtrack.overlay_preview_active => KeymapContextSet::browsing(), - Overlay::Transcript(_) => KeymapContextSet::transcript(), - _ => KeymapContextSet::new(KeymapContext::Pager), + Some(_) => KeymapContextSet::transcript(), + None => KeymapContextSet::new(KeymapContext::Pager), }; return contexts.with_voice_toggle(&self.keymap); } diff --git a/codex-rs/tui/src/app/input/select_mode.rs b/codex-rs/tui/src/app/input/select_mode.rs index 4b6836b12d..116acf7824 100644 --- a/codex-rs/tui/src/app/input/select_mode.rs +++ b/codex-rs/tui/src/app/input/select_mode.rs @@ -1,6 +1,7 @@ //! Transcript selection chord routing kept outside the central application input path. use super::super::*; +use crate::pager_overlay::TranscriptOverlay; impl App { pub(crate) fn transcript_select_exit_key(event: &TuiEvent) -> Option { @@ -15,27 +16,24 @@ impl App { } pub(super) fn select_mode_owns_chord(&self, tui: &tui::Tui, key_event: KeyEvent) -> bool { - let select_mode = matches!( - &self.overlay, - Some(Overlay::Transcript(overlay)) if overlay.is_select_mode() - ) || (tui.is_owned_screen() - && self.overlay.is_none() - && (self.focused_document().map_or_else( - || self.transcript_view.is_select_mode(), - super::super::sidebar_document::Document::is_select_mode, - ))); + let transcript = self.overlay.as_ref().and_then(Overlay::input_transcript); + let select_mode = transcript.is_some_and(TranscriptOverlay::is_select_mode) + || (tui.is_owned_screen() + && self.overlay.is_none() + && (self.focused_document().map_or_else( + || self.transcript_view.is_select_mode(), + super::super::sidebar_document::Document::is_select_mode, + ))); if !select_mode { return false; } let contexts = self.key_chord_contexts(tui); - let search_editing = matches!( - &self.overlay, - Some(Overlay::Transcript(overlay)) if overlay.is_search_editing() - ) || (self.overlay.is_none() - && self.focused_document().map_or_else( - || self.transcript_view.is_search_editing(), - super::super::sidebar_document::Document::is_search_editing, - )); + let search_editing = transcript.is_some_and(TranscriptOverlay::is_search_editing) + || (self.overlay.is_none() + && self.focused_document().map_or_else( + || self.transcript_view.is_search_editing(), + super::super::sidebar_document::Document::is_search_editing, + )); let (code, modifiers) = crate::key_hint::normalize_key_parts(key_event.code, key_event.modifiers); let fixed_search_control = search_editing diff --git a/codex-rs/tui/src/pager_overlay.rs b/codex-rs/tui/src/pager_overlay.rs index 5491371388..3fba14ed09 100644 --- a/codex-rs/tui/src/pager_overlay.rs +++ b/codex-rs/tui/src/pager_overlay.rs @@ -48,6 +48,14 @@ pub(crate) enum Overlay { } impl Overlay { + /// Use for input routing. Only the coding transcript should receive live thread history. + pub(crate) fn input_transcript(&self) -> Option<&TranscriptOverlay> { + match self { + Self::Transcript(view) => Some(view), + _ => None, + } + } + pub(crate) fn new_transcript( cells: Vec>, keymap: PagerKeymap, diff --git a/codex-rs/tui/src/pager_overlay/transcript.rs b/codex-rs/tui/src/pager_overlay/transcript.rs index 9426d755fd..d8643b2859 100644 --- a/codex-rs/tui/src/pager_overlay/transcript.rs +++ b/codex-rs/tui/src/pager_overlay/transcript.rs @@ -33,6 +33,14 @@ pub(crate) struct TranscriptOverlay { is_done: bool, } +impl Overlay { + pub(crate) fn set_keymap_bindings(&mut self, keymap: &RuntimeKeymap) { + if let Self::Transcript(view) = self { + view.set_keymap_bindings(keymap); + } + } +} + impl TranscriptOverlay { pub(crate) fn bookmark(&mut self) -> TranscriptBookmark { self.view.bookmark(&self.cells)