Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

fix(gui): preserve recording masks across previews and fades

RoversX41d6c39f0dc7
diff --git a/docs/thinkterm/recording-overlay.md b/docs/thinkterm/recording-overlay.md
index 62219e1a..882c779e 100644
--- a/docs/thinkterm/recording-overlay.md
+++ b/docs/thinkterm/recording-overlay.md
@@ -26,3 +26,17 @@ closes or the GUI process exits. They are not synchronized to other GUI clients.
This is a visual cover for screen recording. Terminal contents, clipboard copies,
logs, and remote clients retain the original text. Check the recording preview
after changing the window layout or scrolling sensitive content.
+
+## Rendering and validation
+
+Recorded previews and transition captures remove the covered source quads before
+adding the black masks. This keeps text, images, and emoji hidden when the entire
+picture fades or scales. A mask edit invalidates the affected thumbnail and any
+partial rebuild; the card may briefly show its background while rebuilding.
+Snapshots retain their pane's mask layer even after the pane closes. The preview
+mapping uses the terminal renderer's actual text-grid geometry, including padding,
+the navigation bar, split boundaries, and per-pane font metrics.
+
+Regression tests cover partial-opacity/scaled quad replay, texture and gradient
+coordinates, overlapping masks, geometry mapping, and snapshot/cache lifetime.
+These checks do not replace a GUI screen-recording check on the target backend.
diff --git a/wezterm-gui/src/termwindow/content_view.rs b/wezterm-gui/src/termwindow/content_view.rs
index ead88c51..3a673855 100644
--- a/wezterm-gui/src/termwindow/content_view.rs
+++ b/wezterm-gui/src/termwindow/content_view.rs
@@ -194,6 +194,7 @@ pub(crate) struct ContentViewChrome {
/// below the size they were rasterised at, so the text softens as it shrinks
/// -- which is what a window pulling away from you looks like anyway.
pub(crate) struct ContentViewFlight {
+ pub(crate) recording_revision: u64,
pub(crate) surface: crate::quad::HeapQuadAllocator,
/// Where the terminal was when `surface` was recorded.
///
@@ -296,9 +297,24 @@ pub(crate) struct TerminalPreviewSnapshot {
pub splits: Vec<PositionedSplit>,
}
+impl TerminalPreviewSnapshot {
+ pub(crate) fn recording_revision(&self) -> u64 {
+ // Revisions are assigned from one monotonic counter: an edit to any
+ // pane exceeds the previous maximum, without hashes or collisions.
+ self.panes
+ .iter()
+ .map(|pane| pane.recording_layer.revision())
+ .max()
+ .unwrap_or(0)
+ }
+}
+
#[derive(Clone, Debug)]
pub(crate) struct TerminalPreviewPaneSnapshot {
pub pane_id: PaneId,
+ // Retained with the pixels, including after PaneRemoved and during a
+ // sliced rebuild that has not reached this pane yet.
+ pub recording_layer: crate::termwindow::ui::recording_overlay::PaneRecordingLayer,
pub is_active: bool,
pub left: usize,
pub top: usize,
diff --git a/wezterm-gui/src/termwindow/live_overview.rs b/wezterm-gui/src/termwindow/live_overview.rs
index 4e04444b..b9f84630 100644
--- a/wezterm-gui/src/termwindow/live_overview.rs
+++ b/wezterm-gui/src/termwindow/live_overview.rs
@@ -2860,6 +2860,7 @@ fn capture_terminal_snapshot(tab_id: TabId) -> Option<TerminalPreviewSnapshot> {
};
snapshots.push(TerminalPreviewPaneSnapshot {
pane_id: pane.pane_id(),
+ recording_layer: crate::termwindow::ui::recording_overlay::pane_layer(pane.pane_id()),
is_active: positioned.is_active,
left: positioned.left,
top: positioned.top,
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 6d2808b6..7ab4b1cb 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -2618,6 +2618,7 @@ pub struct TermWindow {
/// The most recent full-window view frame, recorded so that closing one
/// has a picture to take away after the view itself is gone.
content_view_last_frame: Option<crate::quad::HeapQuadAllocator>,
+ content_view_last_recording_revision: u64,
/// The heap the next view frame records into; it and `content_view_last_frame`
/// swap every frame so neither is reallocated, and the last frame stays
/// whole until the new recording has succeeded.
@@ -4188,6 +4189,7 @@ impl TermWindow {
content_view_deferred_mux_resize: false,
content_view_fade: None,
content_view_last_frame: None,
+ content_view_last_recording_revision: 0,
content_view_frame_scratch: Default::default(),
next_content_view_id: 1,
registered_content_view_surfaces: HashMap::new(),
diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rs
index c044eac7..870466ac 100644
--- a/wezterm-gui/src/termwindow/render/paint.rs
+++ b/wezterm-gui/src/termwindow/render/paint.rs
@@ -134,6 +134,7 @@ pub(crate) struct PreviewQuadKey {
/// captures (`discard_content_view_captures_after_atlas_recreation`), so
/// nothing here has to stand in for it.
shape_generation: usize,
+ recording_revision: u64,
geometry: PreviewGeometryKey,
}
@@ -162,6 +163,13 @@ pub(crate) struct PreviewGeometryKey {
dpi: usize,
}
+type PreviewRecordingRegion = (
+ mux::pane::PaneId,
+ RectF,
+ RectF,
+ crate::termwindow::ui::recording_overlay::PaneRecordingLayer,
+);
+
/// One card's thumbnail, kept between frames.
pub(crate) struct CachedPreviewQuads {
key: PreviewQuadKey,
@@ -173,13 +181,23 @@ pub(crate) struct CachedPreviewQuads {
/// The card rectangle these quads were laid out in.
area: RectF,
heap: HeapQuadAllocator,
- mask_regions: Vec<(mux::pane::PaneId, RectF, crate::termwindow::ui::recording_overlay::PaneRecordingLayer)>,
/// The card's picture as a texture (WebGpu only). Rendered from `heap`
/// when content changes; composited as a single quad on every other
/// frame, which is what makes an unchanged card nearly free.
texture: Option<Rc<crate::termwindow::webgpu::CardRenderTexture>>,
}
+impl CachedPreviewQuads {
+ fn invalidate_recording_masks(&mut self, revision: u64) {
+ if self.key.recording_revision != revision {
+ self.heap.recycle();
+ self.texture = None;
+ self.key.snapshot = 0;
+ self.key.recording_revision = revision;
+ }
+ }
+}
+
/// What the card preview caches hold, for accounting.
#[derive(Debug, Default, Clone, Copy)]
pub(crate) struct PreviewCacheFootprint {
@@ -225,7 +243,7 @@ pub(crate) struct PreviewRebuildPartial {
#[allow(dead_code)]
snapshot: Arc<crate::termwindow::content_view::TerminalPreviewSnapshot>,
heap: HeapQuadAllocator,
- mask_regions: Vec<(mux::pane::PaneId, RectF, crate::termwindow::ui::recording_overlay::PaneRecordingLayer)>,
+ mask_regions: Vec<PreviewRecordingRegion>,
/// Resume point: the next pane and the next line within it.
pane_idx: usize,
line_idx: usize,
@@ -337,6 +355,7 @@ fn preview_quad_key(
PreviewQuadKey {
snapshot: Arc::as_ptr(&preview.snapshot) as usize,
shape_generation,
+ recording_revision: preview.snapshot.recording_revision(),
geometry: PreviewGeometryKey {
// The font scale is chosen from the card's size, so a resized card
// is a different picture even from the same snapshot. Position is
@@ -1475,6 +1494,11 @@ impl crate::TermWindow {
let Some(flight) = fade.flight.as_ref() else {
return Ok(());
};
+ if flight.recording_revision
+ != crate::termwindow::ui::recording_overlay::recording_mask_revision()
+ {
+ return Ok(());
+ }
// The terminal grid is what travels, and the card's own thumbnail is
// what it lands on, so both ends of the journey are the same picture.
//
@@ -1631,6 +1655,8 @@ impl crate::TermWindow {
source,
destination,
tab_id,
+ recording_revision:
+ crate::termwindow::ui::recording_overlay::recording_mask_revision(),
});
}
}
@@ -1719,6 +1745,8 @@ impl crate::TermWindow {
// Settled: nothing else is on screen to be ordered against.
None => heap.apply_to_clipped(layers, self.surface_clip(), 1.0)?,
}
+ self.content_view_last_recording_revision =
+ crate::termwindow::ui::recording_overlay::recording_mask_revision();
if let Some(previous) = self.content_view_last_frame.replace(heap) {
self.content_view_frame_scratch = previous;
}
@@ -1731,6 +1759,11 @@ impl crate::TermWindow {
/// Composite the recorded frame of a view that has already been closed.
fn paint_departing_content_view(&mut self) -> anyhow::Result<()> {
+ if self.content_view_last_recording_revision
+ != crate::termwindow::ui::recording_overlay::recording_mask_revision()
+ {
+ return Ok(());
+ }
let opacity = self
.content_view_fade_opacity(Instant::now())
.unwrap_or(0.0);
@@ -1949,24 +1982,6 @@ impl crate::TermWindow {
if self.paint_terminal_preview(layers, preview, &mut budget)? {
rebuilt += 1;
}
- // Masks stay live above cached textures, including during sliced rebuilds.
- // Use the geometry of the picture actually being replayed, not a newer snapshot.
- let cache = self.preview_quad_cache.borrow();
- if let Some(cached) = cache.get(&preview.tab_id) {
- let sx = preview.area.width() / cached.area.width().max(1.0);
- let sy = preview.area.height() / cached.area.height().max(1.0);
- let alpha = self.preview_content_alpha(preview) * preview.opacity.clamp(0.0, 1.0);
- for (_, rect, masks) in &cached.mask_regions {
- let frame = euclid::rect(
- preview.area.min_x() + (rect.min_x() - cached.area.min_x()) * sx,
- preview.area.min_y() + (rect.min_y() - cached.area.min_y()) * sy,
- rect.width() * sx, rect.height() * sy,
- );
- if let Some(clip) = preview.clip.intersection(&preview.area) {
- self.paint_recording_mask_layer(masks, frame, clip, layers, alpha)?;
- }
- }
- }
}
// What a frame spent on thumbnails, and how much of that was a card
// whose quads could not be replayed. Without the split, a slow frame
@@ -2063,6 +2078,16 @@ impl crate::TermWindow {
self.shape_generation,
self.preview_scale_estimate(preview),
);
+ // A newly added or moved mask makes the old picture unsafe, even when
+ // the sliced rebuild has no budget. Keep only reusable allocation;
+ // display the card background until the rebuild completes.
+ if let Some(cached) = self
+ .preview_quad_cache
+ .borrow_mut()
+ .get_mut(&preview.tab_id)
+ {
+ cached.invalidate_recording_masks(key.recording_revision);
+ }
let clip = quad_clip_rect(preview.clip, &self.dimensions);
let content_alpha = self.preview_content_alpha(preview) * preview.opacity.clamp(0.0, 1.0);
@@ -2144,7 +2169,7 @@ impl crate::TermWindow {
.preview_quad_cache
.borrow_mut()
.get_mut(&preview.tab_id)
- .filter(|cached| cached.texture.is_some())
+ .filter(|cached| cached.texture.is_some() || cached.heap.quad_count() == 0)
{
heap = std::mem::take(&mut cached.heap);
heap.recycle();
@@ -2201,7 +2226,21 @@ impl crate::TermWindow {
self.update_next_frame_time(Some(Instant::now()));
return Ok(true);
}
- let PreviewRebuildPartial { heap, mask_regions, .. } = partial;
+ let PreviewRebuildPartial {
+ mut heap,
+ mask_regions,
+ ..
+ } = partial;
+ for (_, grid, clip, masks) in &mask_regions {
+ let rects = masks.preview_rects(*grid, *clip);
+ self.occlude_recording_masks(&mut heap, &rects)?;
+ }
+ // Each rebuild slice reads the live layer. Never publish a recording
+ // whose masks changed while the earlier slices were being authored.
+ if preview.snapshot.recording_revision() != key.recording_revision {
+ self.update_next_frame_time(Some(Instant::now()));
+ return Ok(true);
+ }
let prior_texture = self
.preview_quad_cache
.borrow_mut()
@@ -2263,7 +2302,6 @@ impl crate::TermWindow {
snapshot: Arc::clone(&preview.snapshot),
area: preview.area,
heap,
- mask_regions,
texture,
},
);
@@ -2422,7 +2460,7 @@ impl crate::TermWindow {
preview: &TerminalPreviewRequest,
resume_pane: &mut usize,
resume_line: &mut usize,
- mask_regions: &mut Vec<(mux::pane::PaneId, RectF, crate::termwindow::ui::recording_overlay::PaneRecordingLayer)>,
+ mask_regions: &mut Vec<PreviewRecordingRegion>,
deadline: Instant,
) -> anyhow::Result<bool> {
let snapshot = &preview.snapshot;
@@ -2581,9 +2619,6 @@ impl crate::TermWindow {
let pane_width = pane.width as f32 * cell_width;
let pane_height = pane.height as f32 * cell_height;
let pane_rect = euclid::rect(pane_x, pane_y, pane_width, pane_height);
- if mask_regions.last().is_none_or(|(id, _, _)| *id != pane.pane_id) {
- mask_regions.push((pane.pane_id, pane_rect, crate::termwindow::ui::recording_overlay::pane_layer(pane.pane_id)));
- }
let Some(pane_bounds) = pane_rect.intersection(&preview.area) else {
continue;
};
@@ -2627,6 +2662,18 @@ impl crate::TermWindow {
};
let grid_top = pane_rect.min_y() + pane_height * nav_fraction;
let grid_height = pane_height * (1.0 - nav_fraction);
+ if mask_regions
+ .last()
+ .is_none_or(|(id, _, _, _)| *id != pane.pane_id)
+ {
+ let masks = pane.recording_layer.clone();
+ mask_regions.push((
+ pane.pane_id,
+ euclid::rect(pane_rect.min_x(), grid_top, pane_width, grid_height),
+ pane_bounds,
+ masks,
+ ));
+ }
// Pane placement remains in the root grid so every split keeps
// the same outer frame. Content inside that frame uses the pane's
@@ -4414,6 +4461,7 @@ impl crate::TermWindow {
#[cfg(test)]
mod tests {
use super::*;
+ use crate::quad::TripleLayerQuadAllocatorTrait;
fn test_preview(area: RectF) -> TerminalPreviewRequest {
TerminalPreviewRequest {
@@ -4438,6 +4486,32 @@ mod tests {
}
}
+ #[test]
+ fn changed_recording_masks_retire_cached_source_quads_before_rebuild() {
+ let preview = test_preview(euclid::rect(10.0, 20.0, 400.0, 260.0));
+ let mut heap = HeapQuadAllocator::default();
+ heap.allocate(1)
+ .unwrap()
+ .set_position(0.0, 0.0, 100.0, 100.0);
+ let mut cached = CachedPreviewQuads {
+ key: preview_quad_key(&preview, &test_dimensions(), 3, 1.0),
+ snapshot: Arc::clone(&preview.snapshot),
+ area: preview.area,
+ heap,
+ texture: None,
+ };
+ cached.invalidate_recording_masks(0);
+ assert_eq!(cached.heap.quad_count(), 1);
+ let partial_key = cached.key;
+ cached.invalidate_recording_masks(7);
+ assert_eq!(cached.heap.quad_count(), 0);
+ assert_eq!(cached.key.snapshot, 0); // no real snapshot can hit this placeholder
+ assert_ne!(partial_key, cached.key); // an in-flight old rebuild is retired too
+ let mut fresh_key = preview_quad_key(&preview, &test_dimensions(), 3, 1.0);
+ fresh_key.recording_revision = 7;
+ assert_ne!(cached.key, fresh_key);
+ }
+
/// The whole point of the cache: an unchanged snapshot in an unchanged card
/// replays instead of being rebuilt.
#[test]
diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rs
index 3cfaf4ee..c437ddc0 100644
--- a/wezterm-gui/src/termwindow/render/pane.rs
+++ b/wezterm-gui/src/termwindow/render/pane.rs
@@ -1795,6 +1795,21 @@ impl crate::TermWindow {
+ (pos.top as f32 * global_render_metrics.cell_size.height as f32)
+ pane_nav_height as f32;
+ if let Ok(frame) = self.pane_frame_rect(pos) {
+ self.update_recording_mask_grid(
+ pane_id,
+ frame,
+ euclid::rect(
+ left_pixel_x,
+ pane_top_pixel_y,
+ // Preview snapshots contain the full logical grid,
+ // including columns/rows clipped by this window.
+ dims.cols as f32 * pane_render_metrics.cell_size.width as f32,
+ dims.viewport_rows as f32 * pane_render_metrics.cell_size.height as f32,
+ ),
+ );
+ }
+
if pos.is_active {
self.update_text_cursor(
&cursor,
diff --git a/wezterm-gui/src/termwindow/ui/recording_overlay.rs b/wezterm-gui/src/termwindow/ui/recording_overlay.rs
index 0d289472..96b2a8d5 100644
--- a/wezterm-gui/src/termwindow/ui/recording_overlay.rs
+++ b/wezterm-gui/src/termwindow/ui/recording_overlay.rs
@@ -5,6 +5,7 @@ use crate::ui::{DrawContext, SvgIcon};
use crate::utilsprites::RenderMetrics;
use mux::pane::PaneId;
use std::collections::HashMap;
+use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, LazyLock, Mutex};
use window::color::LinearRgba;
use window::{KeyCode, KeyEvent, MouseCursor, MouseEvent, MouseEventKind, MousePress, WindowOps};
@@ -25,12 +26,82 @@ struct Rect {
// GUI-local state follows a pane between windows; no terminal or mux data changes.
// Rectangles are normalized to the pane frame, so previews reuse the same geometry.
-#[derive(Clone, Default)]
-pub(crate) struct PaneRecordingLayer(Arc<Mutex<Vec<Rect>>>);
+#[derive(Clone, Debug, Default)]
+pub(crate) struct PaneRecordingLayer(Arc<Mutex<PaneRecordingState>>);
+
+#[derive(Debug, Default)]
+struct PaneRecordingState {
+ masks: Vec<Rect>,
+ // The actual text grid, relative to the editable pane frame. This includes
+ // the renderer's padding, nav bar and effective per-pane font metrics.
+ grid: Option<Rect>,
+ revision: u64,
+}
+
+static MASK_REVISION: AtomicU64 = AtomicU64::new(0);
+
+pub(crate) fn recording_mask_revision() -> u64 {
+ MASK_REVISION.load(Ordering::Relaxed)
+}
+
+fn next_revision() -> u64 {
+ MASK_REVISION.fetch_add(1, Ordering::Relaxed) + 1
+}
impl PaneRecordingLayer {
+ pub(crate) fn revision(&self) -> u64 {
+ self.0.lock().unwrap().revision
+ }
+
+ pub(crate) fn preview_rects(
+ &self,
+ target_grid: window::RectF,
+ clip: window::RectF,
+ ) -> Vec<window::RectF> {
+ let state = self.0.lock().unwrap();
+ if state.masks.is_empty() {
+ return Vec::new();
+ }
+ let Some(grid) = state.grid.filter(|grid| grid.w > 0.0 && grid.h > 0.0) else {
+ // A source pane that has not painted since its masks were created
+ // has no trustworthy grid mapping yet. Keep its preview covered.
+ return vec![clip];
+ };
+ state
+ .masks
+ .iter()
+ .filter_map(|mask| {
+ Rect {
+ x: (mask.x - grid.x) / grid.w,
+ y: (mask.y - grid.y) / grid.h,
+ w: mask.w / grid.w,
+ h: mask.h / grid.h,
+ }
+ .in_frame(target_grid)
+ .intersection(&clip)
+ })
+ .collect()
+ }
+
+ fn set_grid(&self, frame: window::RectF, grid: window::RectF) -> bool {
+ let grid = Rect {
+ x: (grid.min_x() - frame.min_x()) / frame.width().max(1.0),
+ y: (grid.min_y() - frame.min_y()) / frame.height().max(1.0),
+ w: grid.width() / frame.width().max(1.0),
+ h: grid.height() / frame.height().max(1.0),
+ };
+ let mut state = self.0.lock().unwrap();
+ if state.grid != Some(grid) {
+ state.grid = Some(grid);
+ if !state.masks.is_empty() {
+ state.revision = next_revision();
+ return true;
+ }
+ }
+ false
+ }
fn is_empty(&self) -> bool {
- self.0.lock().unwrap().is_empty()
+ self.0.lock().unwrap().masks.is_empty()
}
}
@@ -55,7 +126,12 @@ pub(crate) fn pane_layer(pane_id: PaneId) -> PaneRecordingLayer {
}
fn save_pane_masks(pane_id: PaneId, masks: Vec<Rect>) {
- *pane_layer(pane_id).0.lock().unwrap() = masks;
+ let layer = pane_layer(pane_id);
+ let mut state = layer.0.lock().unwrap();
+ if state.masks != masks {
+ state.masks = masks;
+ state.revision = next_revision();
+ }
}
impl Rect {
@@ -165,6 +241,7 @@ impl RecordingOverlay {
.0
.lock()
.unwrap()
+ .masks
.iter()
.map(|r| Rect {
x: r.x * size.0,
@@ -365,6 +442,49 @@ impl crate::TermWindow {
}
}
+ pub(crate) fn update_recording_mask_grid(
+ &self,
+ pane_id: PaneId,
+ frame: window::RectF,
+ grid: window::RectF,
+ ) {
+ if let Some(masks) = pane_masks(pane_id) {
+ if masks.set_grid(frame, grid) {
+ crate::frontend::front_end().invalidate_all_windows();
+ }
+ }
+ }
+
+ pub(crate) fn occlude_recording_masks(
+ &self,
+ heap: &mut crate::quad::HeapQuadAllocator,
+ rects: &[window::RectF],
+ ) -> anyhow::Result<()> {
+ let clips: Vec<_> = rects
+ .iter()
+ .map(|rect| {
+ crate::quad::QuadClipRect::from_top_left_pixels(
+ rect.min_x(),
+ rect.min_y(),
+ rect.max_x(),
+ rect.max_y(),
+ &self.dimensions,
+ )
+ })
+ .collect();
+ heap.occlude(&clips);
+ let mut layers = TripleLayerQuadAllocator::Heap(heap);
+ for rect in rects {
+ self.filled_rectangle(
+ &mut layers,
+ 2,
+ *rect,
+ LinearRgba::with_components(0.0, 0.0, 0.0, 1.0),
+ )?;
+ }
+ Ok(())
+ }
+
// This runs inside the terminal world, so a recorded transition includes it.
pub(crate) fn paint_pane_recording_masks(
&self,
@@ -373,6 +493,22 @@ impl crate::TermWindow {
layers: &mut TripleLayerQuadAllocator,
) -> anyhow::Result<()> {
let black = LinearRgba::with_components(0.0, 0.0, 0.0, 1.0);
+ if let TripleLayerQuadAllocator::Heap(heap) = layers {
+ let rects = pane_masks(pane_id)
+ .map(|masks| {
+ masks
+ .0
+ .lock()
+ .unwrap()
+ .masks
+ .iter()
+ .filter_map(|mask| mask.in_frame(frame).intersection(&frame))
+ .collect::<Vec<_>>()
+ })
+ .unwrap_or_default();
+ self.occlude_recording_masks(heap, &rects)?;
+ return Ok(());
+ }
let editing =
self.recording_overlay.editing && self.recording_overlay.pane_id == Some(pane_id);
if !editing {
@@ -444,7 +580,7 @@ impl crate::TermWindow {
layers: &mut TripleLayerQuadAllocator,
opacity: f32,
) -> anyhow::Result<()> {
- for rect in masks.0.lock().unwrap().iter() {
+ for rect in masks.0.lock().unwrap().masks.iter() {
if let Some(rect) = rect.in_frame(frame).intersection(&clip) {
self.filled_rectangle(
layers,
@@ -959,13 +1095,13 @@ mod tests {
h: 0.1,
};
save_pane_masks(id, vec![rect]);
- assert_eq!(*cached.0.lock().unwrap(), vec![rect]);
+ assert_eq!(cached.0.lock().unwrap().masks, vec![rect]);
save_pane_masks(id, vec![]);
assert!(cached.is_empty());
save_pane_masks(id, vec![rect]);
forget_pane(id);
assert!(pane_masks(id).is_none());
- assert_eq!(*cached.0.lock().unwrap(), vec![rect]);
+ assert_eq!(cached.0.lock().unwrap().masks, vec![rect]);
}
#[test]
@@ -1020,4 +1156,156 @@ mod tests {
assert!(state.pressed_button.is_none());
assert!(state.finish_key.is_none());
}
+ #[test]
+ fn preview_masks_follow_text_grid_padding_splits_and_pane_font_metrics() {
+ for (frame, grid, cell) in [
+ // Default horizontal one-cell and vertical half-cell padding plus nav.
+ (
+ euclid::rect(280.0, 40.0, 900.0, 600.0),
+ euclid::rect(294.0, 84.0, 868.0, 532.0),
+ (14.0, 28.0),
+ ),
+ // Split pane begins half a root cell before its own content grid.
+ (
+ euclid::rect(701.0, 40.0, 479.0, 600.0),
+ euclid::rect(708.0, 84.0, 448.0, 532.0),
+ (14.0, 28.0),
+ ),
+ // Independent pane zoom and a different window/sidebar origin.
+ (
+ euclid::rect(61.0, 200.0, 1200.0, 900.0),
+ euclid::rect(82.0, 260.0, 1155.0, 798.0),
+ (21.0, 42.0),
+ ),
+ ] {
+ let layer = PaneRecordingLayer::default();
+ let mask = Rect {
+ x: grid.min_x() - frame.min_x(),
+ y: grid.min_y() - frame.min_y(),
+ w: cell.0 * 4.0,
+ h: cell.1,
+ }
+ .normalized((frame.width(), frame.height()));
+ layer.0.lock().unwrap().masks = vec![mask];
+ layer.set_grid(frame, grid);
+ let target = euclid::rect(25.0, 80.0, grid.width() / 4.0, grid.height() / 4.0);
+ let result = layer.preview_rects(target, euclid::rect(0.0, 0.0, 1000.0, 1000.0));
+ assert_eq!(result.len(), 1);
+ for (got, wanted) in [
+ (result[0].min_x(), target.min_x()),
+ (result[0].min_y(), target.min_y()),
+ (result[0].width(), cell.0),
+ (result[0].height(), cell.1 / 4.0),
+ ] {
+ assert!((got - wanted).abs() < 0.0001, "{} != {}", got, wanted);
+ }
+ }
+ }
+
+ #[test]
+ fn missing_grid_only_covers_masked_panes_and_geometry_changes_invalidate() {
+ let layer = PaneRecordingLayer::default();
+ let frame = euclid::rect(0.0, 0.0, 100.0, 100.0);
+ assert!(layer.preview_rects(frame, frame).is_empty());
+ layer.0.lock().unwrap().masks.push(Rect {
+ x: 0.1,
+ y: 0.1,
+ w: 0.2,
+ h: 0.2,
+ });
+ assert_eq!(layer.preview_rects(frame, frame), vec![frame]);
+ layer.set_grid(frame, euclid::rect(10.0, 10.0, 80.0, 80.0));
+ let first = layer.revision();
+ layer.set_grid(frame, euclid::rect(10.0, 10.0, 80.0, 80.0));
+ assert_eq!(layer.revision(), first);
+ layer.set_grid(frame, euclid::rect(20.0, 10.0, 70.0, 80.0));
+ assert!(layer.revision() > first);
+ }
+
+ #[test]
+ fn snapshot_keeps_masks_for_unrendered_or_removed_panes() {
+ use crate::termwindow::content_view::{
+ TerminalPreviewPaneSnapshot, TerminalPreviewSnapshot,
+ };
+ let id = usize::MAX - 111;
+ let mask = Rect {
+ x: 0.1,
+ y: 0.1,
+ w: 0.2,
+ h: 0.2,
+ };
+ save_pane_masks(id, vec![mask]);
+ let snapshot = TerminalPreviewSnapshot {
+ tab_size: Default::default(),
+ splits: Vec::new(),
+ panes: vec![TerminalPreviewPaneSnapshot {
+ pane_id: id,
+ recording_layer: pane_layer(id),
+ is_active: true,
+ left: 0,
+ top: 0,
+ width: 0,
+ height: 0,
+ cols: 0,
+ rows: 0,
+ resolved_top: 0,
+ lines: Vec::new(),
+ box_pixel_height: 0,
+ dimensions: Default::default(),
+ palette: Default::default(),
+ cursor: Default::default(),
+ }],
+ };
+ let first = snapshot.recording_revision();
+ assert!(first > 0); // zero-sized/off-card panes participate in both key checks
+ save_pane_masks(id, vec![mask, mask]);
+ let edited = snapshot.recording_revision();
+ assert!(edited > first); // retires both a cached picture and its old partial
+ forget_pane(id);
+ assert_eq!(snapshot.recording_revision(), edited);
+ assert_eq!(
+ snapshot.panes[0]
+ .recording_layer
+ .0
+ .lock()
+ .unwrap()
+ .masks
+ .len(),
+ 2
+ );
+ let frame = euclid::rect(0.0, 0.0, 100.0, 100.0);
+ assert_eq!(
+ snapshot.panes[0]
+ .recording_layer
+ .preview_rects(frame, frame),
+ vec![frame]
+ );
+ }
+ #[test]
+ fn preview_uses_full_source_grid_when_the_window_clips_rows_or_columns() {
+ let layer = PaneRecordingLayer::default();
+ let frame = euclid::rect(100.0, 20.0, 800.0, 600.0);
+ let grid = euclid::rect(112.0, 60.0, 1200.0, 960.0);
+ // A visible cell near the right edge; the snapshot also contains
+ // source columns/rows outside the current window's clipped viewport.
+ layer.0.lock().unwrap().masks = vec![Rect {
+ x: 12.0 + 60.0 * 12.0,
+ y: 40.0 + 20.0 * 24.0,
+ w: 12.0,
+ h: 24.0,
+ }
+ .normalized((frame.width(), frame.height()))];
+ layer.set_grid(frame, grid);
+ let preview_grid = euclid::rect(20.0, 30.0, 300.0, 240.0);
+ let result = layer.preview_rects(preview_grid, preview_grid);
+ assert_eq!(result.len(), 1);
+ for (got, wanted) in [
+ (result[0].min_x(), 200.0),
+ (result[0].min_y(), 150.0),
+ (result[0].width(), 3.0),
+ (result[0].height(), 6.0),
+ ] {
+ assert!((got - wanted).abs() < 0.0001, "{} != {}", got, wanted);
+ }
+ }
}