mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Make TUI workspace divider drags more responsive (#63997)
## Why Rapid mouse motion can queue more drag reports than the TUI needs to resize a pane. Rebuilding sidebar document layouts at each preview width also adds work while the divider moves. ## What changed - Share drag handling between the Command Center and sidebar dividers. Let users grab either column of the Command Center gutter, keep the grab offset, and highlight the divider on hover and during a drag. - Use the release position for the final width. If focus loss interrupts a valid drag, keep the last width. When the terminal holds image pixels, show a guide and defer pane reflow until the drag ends. - Batch consecutive mouse motion reports during divider drags while preserving input order at batch boundaries. Rewrap cached sidebar document content during live previews and rebuild its layout at the final width. ## Testing Cover gutter hit testing, grab offsets, release and focus-loss behavior, drag batching at input boundaries, and document layout reuse during preview followed by a rebuild. GitOrigin-RevId: 949a805a42d269f4bac1a86ac7e4b7f8c2a4cacf
This commit is contained in:
@@ -15,6 +15,11 @@ pub(crate) enum DocumentPosition {
|
||||
}
|
||||
|
||||
impl TranscriptView {
|
||||
/// During a live resize, wrap the already rendered file instead of parsing it at every width.
|
||||
pub(crate) fn set_document_resize_preview(&mut self, active: bool) {
|
||||
self.cache.set_document_resize_preview(active);
|
||||
}
|
||||
|
||||
pub(crate) fn document_position(&self) -> DocumentPosition {
|
||||
match self.position {
|
||||
Position::Reading(anchor) => DocumentPosition::Offset(anchor.offset),
|
||||
|
||||
@@ -118,6 +118,7 @@ fn is_rich_user_prompt(cell: &dyn HistoryCell, mode: HistoryRenderMode) -> bool
|
||||
#[derive(Default)]
|
||||
pub(super) struct LayoutCache {
|
||||
entries: Vec<CachedLayout>,
|
||||
document_resize_preview: bool,
|
||||
frame: u64,
|
||||
render_state: Option<RenderState>,
|
||||
}
|
||||
@@ -331,6 +332,14 @@ impl TranscriptView {
|
||||
}
|
||||
|
||||
impl LayoutCache {
|
||||
pub(super) fn set_document_resize_preview(&mut self, active: bool) {
|
||||
if self.document_resize_preview && !active {
|
||||
// Markdown tables and other width-dependent content need an exact final layout.
|
||||
self.clear();
|
||||
}
|
||||
self.document_resize_preview = active;
|
||||
}
|
||||
|
||||
pub(super) fn has_mutable_source(&self) -> bool {
|
||||
self.entries.iter().any(|entry| {
|
||||
entry
|
||||
@@ -366,14 +375,20 @@ impl LayoutCache {
|
||||
let source = Arc::downgrade(cell);
|
||||
let animation_tick = cell.transcript_animation_tick();
|
||||
if let Some(index) = self.entries.iter().position(|entry| {
|
||||
entry.width == width
|
||||
(entry.width == width || self.document_resize_preview)
|
||||
&& entry.presentation == presentation
|
||||
&& entry.source.ptr_eq(&source)
|
||||
&& (entry.rendered_frame == self.frame
|
||||
|| (cell.has_stable_transcript_height()
|
||||
&& entry.animation_tick == animation_tick))
|
||||
}) {
|
||||
let layout = Arc::clone(&self.entries[index].layout);
|
||||
let entry = &mut self.entries[index];
|
||||
if entry.width != width {
|
||||
// Keep the document's styled source and links while the divider moves.
|
||||
entry.layout = Arc::new(entry.layout.rewrap(width));
|
||||
entry.width = width;
|
||||
}
|
||||
let layout = Arc::clone(&entry.layout);
|
||||
if index + 1 != self.entries.len() {
|
||||
let entry = self.entries.remove(index);
|
||||
self.entries.push(entry);
|
||||
|
||||
@@ -78,6 +78,18 @@ fn layouts_refresh_for_width_animation_and_mutable_frames() {
|
||||
cell.renders.load(Ordering::Relaxed),
|
||||
3 + usize::from(mutable)
|
||||
);
|
||||
// A document drag wraps cached text across widths. On release, restore
|
||||
// width-specific rendering even when the last preview had the same width.
|
||||
let before_drag = cell.renders.load(Ordering::Relaxed);
|
||||
cache.set_document_resize_preview(/*active*/ true);
|
||||
let narrow = get(&mut cache, /*width*/ 4);
|
||||
assert!(narrow.row_count() > 1);
|
||||
let wide = get(&mut cache, /*width*/ 10);
|
||||
assert_eq!(wide.row_count(), 1);
|
||||
assert_eq!(cell.renders.load(Ordering::Relaxed), before_drag);
|
||||
cache.set_document_resize_preview(/*active*/ false);
|
||||
get(&mut cache, /*width*/ 10);
|
||||
assert_eq!(cell.renders.load(Ordering::Relaxed), before_drag + 1);
|
||||
crate::terminal_palette::with_test_default_colors(
|
||||
crate::terminal_probe::DefaultColors {
|
||||
fg: (12, 34, 56),
|
||||
@@ -88,7 +100,7 @@ fn layouts_refresh_for_width_animation_and_mutable_frames() {
|
||||
get(&mut cache, /*width*/ 10);
|
||||
assert_eq!(
|
||||
cell.renders.load(Ordering::Relaxed),
|
||||
4 + usize::from(mutable)
|
||||
5 + usize::from(mutable)
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user