Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: cache pager output in picker previews to avoid UI lag (#2021)
Maximilian Roos456381dc7f69
diff --git a/src/commands/picker/items.rs b/src/commands/picker/items.rsindex 51702e5e0..e13546785 100644--- a/src/commands/picker/items.rs+++ b/src/commands/picker/items.rs@@ -156,21 +156,43 @@ impl WorktreeSkimItem {}/// Render preview for the given mode with specified dimensions.- /// Uses cache if available, otherwise computes and caches.- /// Post-processing (diff pager, markdown render) applied at display time.+ ///+ /// Uses cache if available, otherwise computes and caches. Diff-mode pager+ /// output is included in the cached value (via [`Self::compute_and_page_preview`])+ /// so that skim's event-loop thread — which calls `preview()` synchronously —+ /// never spawns a pager subprocess.fn preview_for_mode(&self, mode: PreviewMode, width: usize, height: usize) -> String {let cache_key = (self.branch_name.clone(), mode);let content = self.preview_cache.entry(cache_key)- .or_insert_with(|| Self::compute_preview(&self.item, mode, width, height))+ .or_insert_with(|| Self::compute_and_page_preview(&self.item, mode, width, height)).value().clone();- // Post-processing at display time (not cached)match mode {+ // Summary post-processing is cheap (string formatting, no subprocess).+ // Applied at display time because generate_and_cache_summary() inserts+ // raw LLM output.PreviewMode::Summary => super::summary::render_summary(&content, width),+ _ => content,+ }+ }++ /// Compute preview and apply pager for diff modes.+ ///+ /// Both the inline cache-miss path and background pre-computation use this so+ /// that the cache always stores display-ready content (no pager subprocess+ /// needed at render time).+ pub(super) fn compute_and_page_preview(+ item: &ListItem,+ mode: PreviewMode,+ width: usize,+ height: usize,+ ) -> String {+ let content = Self::compute_preview(item, mode, width, height);+ match mode {PreviewMode::WorkingTree | PreviewMode::BranchDiff | PreviewMode::UpstreamDiff => {if let Some(pager_cmd) = diff_pager() {pipe_through_pager(&content, pager_cmd, width)@@ -178,11 +200,11 @@ impl WorktreeSkimItem {content}}- PreviewMode::Log => content,+ _ => content,}}- /// Compute preview for any mode. Called from cache miss and background pre-computation.+ /// Compute raw preview for any mode.pub(super) fn compute_preview(item: &ListItem,mode: PreviewMode,diff --git a/src/commands/picker/mod.rs b/src/commands/picker/mod.rsindex cb2494236..aef66a53a 100644--- a/src/commands/picker/mod.rs+++ b/src/commands/picker/mod.rs@@ -529,7 +529,12 @@ pub fn handle_picker(rayon::spawn(move || {let cache_key = (item.branch_name().to_string(), mode);cache.entry(cache_key).or_insert_with(|| {- WorktreeSkimItem::compute_preview(&item, mode, preview_width, preview_height)+ WorktreeSkimItem::compute_and_page_preview(+ &item,+ mode,+ preview_width,+ preview_height,+ )});});}