mirror of
https://github.com/openai/codex.git
synced 2026-11-21 22:50:37 +00:00
## What changed - Add the disabled-by-default `tui_workspace` feature for the owned transcript view. At terminal widths of at least 100 columns, show the parent conversation beside its side conversation, with only the focused composer accepting input. - Retain the inactive conversation's transcript, draft, and status, and restore reading and search state when switching focus. - Keep drawing and input paused until history replay completes, while refreshing skills in the background. ## Testing Add snapshots and regression tests for pane resizing and composer styling, retained streaming output, history search after replay, pending skills refreshes, and modal input protection. GitOrigin-RevId: 68938f263353b0cd3a9e9562e06293bfc8251cc6
165 lines
6.1 KiB
Rust
165 lines
6.1 KiB
Rust
//! Retain displayed revisions while selecting or reading across live updates and history replay.
|
|
//! Pinned layouts respect manual disclosures; Find's expansion is applied only at display time.
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use super::*;
|
|
|
|
#[derive(Clone)]
|
|
pub(super) struct ViewSnapshot {
|
|
pub(super) cells: Arc<[Arc<dyn HistoryCell>]>,
|
|
pub(super) pinned: HashMap<EntryKey, Arc<TextLayout>>,
|
|
pub(super) activities: HashMap<EntryKey, Arc<[String]>>,
|
|
// Hidden live text cannot be reconstructed from the pinned compact display.
|
|
pub(super) search_live: Option<Arc<TextLayout>>,
|
|
}
|
|
|
|
impl TranscriptView {
|
|
pub(super) fn snapshot(&self) -> Option<&ViewSnapshot> {
|
|
self.selection
|
|
.as_ref()
|
|
.map(|selection| &selection.snapshot)
|
|
.or(self.held_reading.as_ref())
|
|
}
|
|
|
|
pub(super) fn snapshot_mut(&mut self) -> Option<&mut ViewSnapshot> {
|
|
self.selection
|
|
.as_mut()
|
|
.map(|selection| &mut selection.snapshot)
|
|
.or(self.held_reading.as_mut())
|
|
}
|
|
|
|
/// Clone the handle before mutating view state, without copying cells per frame.
|
|
pub(super) fn snapshot_cells(&self) -> Option<Arc<[Arc<dyn HistoryCell>]>> {
|
|
self.snapshot().map(|snapshot| Arc::clone(&snapshot.cells))
|
|
}
|
|
|
|
pub(super) fn capture_snapshot(&mut self, cells: &[Arc<dyn HistoryCell>]) -> ViewSnapshot {
|
|
let cells = self.snapshot_cells().unwrap_or_else(|| Arc::from(cells));
|
|
let mut pinned = self
|
|
.snapshot()
|
|
.map(|snapshot| snapshot.pinned.clone())
|
|
.unwrap_or_default();
|
|
let mut activities = self
|
|
.snapshot()
|
|
.map(|snapshot| snapshot.activities.clone())
|
|
.unwrap_or_default();
|
|
pinned.extend(
|
|
self.visible
|
|
.iter()
|
|
.map(|visible| (visible.key, Arc::clone(&visible.layout))),
|
|
);
|
|
activities.extend(
|
|
self.visible
|
|
.iter()
|
|
.map(|visible| (visible.key, Arc::clone(&visible.activity_ids))),
|
|
);
|
|
if let Some(live) = self.base_layout(&cells, cells.len()) {
|
|
pinned.insert(EntryKey::Live, live);
|
|
activities.insert(
|
|
EntryKey::Live,
|
|
self.displayed_activity_ids(&cells, cells.len()),
|
|
);
|
|
}
|
|
// visible may contain the expanded match. Pin its underlying revision even when
|
|
// the hit has moved offscreen, so selection never retains a temporary expansion.
|
|
if let Some(anchor) = self.search.match_anchor() {
|
|
let index = self.resolve(&cells, anchor);
|
|
let base = self
|
|
.base_layout(&cells, index)
|
|
.unwrap_or_else(|| Arc::new(TextLayout::new(Vec::new(), self.area.width)));
|
|
pinned.insert(anchor.key, base);
|
|
}
|
|
ViewSnapshot {
|
|
cells,
|
|
pinned,
|
|
activities,
|
|
search_live: self
|
|
.snapshot()
|
|
.and_then(|snapshot| snapshot.search_live.clone())
|
|
.or_else(|| self.search.live.clone()),
|
|
}
|
|
}
|
|
|
|
/// Keep the parked reading revision and rebind a quiet tail to its replayed identity.
|
|
pub(crate) fn restore_after_replay(
|
|
&mut self,
|
|
parked: &[Arc<dyn HistoryCell>],
|
|
replayed: &[Arc<dyn HistoryCell>],
|
|
replay_may_have_output: bool,
|
|
replayed_live: Option<ActiveCellTranscriptKey>,
|
|
) {
|
|
if matches!(self.position, Position::Reading(_)) && self.snapshot().is_none() {
|
|
self.held_reading = Some(self.capture_snapshot(parked));
|
|
}
|
|
if !replay_may_have_output {
|
|
self.last_tail = replayed.last().map(EntryKey::cell);
|
|
// The parked display and replayed widget may represent the same stream differently.
|
|
self.live_key = replayed_live.map(|mut key| {
|
|
key.cacheable = false;
|
|
(self.area.width, key)
|
|
});
|
|
}
|
|
}
|
|
|
|
/// Keep a live, mutable, or replaced cell revision while reading inside it. Navigation
|
|
/// rejoins current history when it reaches a surviving cell.
|
|
pub(super) fn hold_live_reading(
|
|
&mut self,
|
|
cells: &[Arc<dyn HistoryCell>],
|
|
layout: Arc<TextLayout>,
|
|
) {
|
|
if self.selection.is_some() {
|
|
return;
|
|
}
|
|
let Position::Reading(anchor) = self.position else {
|
|
self.release_live_reading();
|
|
return;
|
|
};
|
|
let mutable_cell = cells.get(anchor.index).is_some_and(|cell| {
|
|
EntryKey::cell(cell) == anchor.key
|
|
&& (!cell.has_stable_transcript_height()
|
|
|| cell.transcript_animation_tick().is_some())
|
|
});
|
|
if anchor.key == EntryKey::Live || mutable_cell {
|
|
if self
|
|
.held_reading
|
|
.as_ref()
|
|
.is_none_or(|snapshot| !snapshot.pinned.contains_key(&anchor.key))
|
|
{
|
|
self.held_reading = None;
|
|
let mut snapshot = self.capture_snapshot(cells);
|
|
if !self.is_search_expanded(anchor.key) {
|
|
snapshot.pinned.insert(anchor.key, layout);
|
|
}
|
|
self.held_reading = Some(snapshot);
|
|
}
|
|
} else if self.held_reading.is_some()
|
|
&& let Some(index) = cells
|
|
.iter()
|
|
.position(|cell| EntryKey::cell(cell) == anchor.key)
|
|
{
|
|
self.release_live_reading();
|
|
self.position = Position::Reading(Anchor { index, ..anchor });
|
|
}
|
|
}
|
|
|
|
/// Search offsets belong to the held revision and must be refreshed when it is released.
|
|
pub(super) fn release_live_reading(&mut self) {
|
|
if self.held_reading.take().is_some() {
|
|
self.invalidate_held_search();
|
|
}
|
|
}
|
|
|
|
pub(super) fn rewrap_snapshot(&mut self, width: u16) {
|
|
if let Some(snapshot) = self.snapshot_mut() {
|
|
for layout in snapshot.pinned.values_mut() {
|
|
*layout = Arc::new(layout.rewrap(width));
|
|
}
|
|
if let Some(layout) = &mut snapshot.search_live {
|
|
*layout = Arc::new(layout.rewrap(width));
|
|
}
|
|
}
|
|
}
|
|
}
|