Repository navigation
Conversation
Extracted from #11866 by @dcieslak19973. Preserve explicit target-group scoping while unpinned previews reuse the parked tab.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change adds worktree-scoped parked preview reuse across editor split groups. Merge Risk: 🔵 Low · up to Parked preview reuse now works across editor groups, but in a protected-preview ordering case it may create an additional preview tab rather than reusing an eligible parked tab. This is a bounded editor-tab behavior issue and should be addressed before relying on complete preview reuse. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: eaa8876f-4ec7-4aa2-8f2c-05518b851d2a
📒 Files selected for processing (9)
src/renderer/src/store/slices/editor-parked-preview-reuse.test.tssrc/renderer/src/store/slices/editor/actions/markdown-preview-actions.tssrc/renderer/src/store/slices/editor/actions/open-conflict-file.tssrc/renderer/src/store/slices/editor/actions/open-conflict-review.tssrc/renderer/src/store/slices/editor/actions/open-file-action.tssrc/renderer/src/store/slices/editor/actions/open-file-apply.tssrc/renderer/src/store/slices/editor/actions/open-history-diff.tssrc/renderer/src/store/slices/editor/actions/open-unstaged-diff.tssrc/renderer/src/store/slices/editor/tabs/workspace-editor-item.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
| }) | ||
| store.getState().focusGroup('wt-1', groupAId) | ||
|
|
||
| store.getState().openDiff('wt-1', '/repo/a.ts', 'a.ts', 'typescript', false, { preview: true }) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert the parked group’s active tab.
The current assertions verify placement, but not selection. Assert that state.groupsByWorktree['wt-1'] group B has activeTabId equal to the existing preview tab ID. Otherwise, the preview can remain parked while the test passes.
| const previewTab = tabsForWorktree.find( | ||
| (tab) => | ||
| (!pinnedGroupId || tab.groupId === pinnedGroupId) && | ||
| tab.isPreview && | ||
| isEditorTabContentType(tab.contentType) | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Skip protected previews when selecting a replacement slot.
If the first worktree preview shares its entity with another editor tab, this function returns null at Line 95. It does not inspect a later unshared preview in another group. The caller then creates an additional preview instead of reusing that parked preview.
Select the first preview that is both eligible and not shared.
Proposed fix
- const previewTab = tabsForWorktree.find(
- (tab) =>
- (!pinnedGroupId || tab.groupId === pinnedGroupId) &&
- tab.isPreview &&
- isEditorTabContentType(tab.contentType)
- )
+ const previewTab = tabsForWorktree.find(
+ (candidate) =>
+ (!pinnedGroupId || candidate.groupId === pinnedGroupId) &&
+ candidate.isPreview &&
+ isEditorTabContentType(candidate.contentType) &&
+ !tabsForWorktree.some(
+ (tab) =>
+ tab.id !== candidate.id &&
+ tab.entityId === candidate.entityId &&
+ isEditorTabContentType(tab.contentType)
+ )
+ )📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const previewTab = tabsForWorktree.find( | |
| (tab) => | |
| (!pinnedGroupId || tab.groupId === pinnedGroupId) && | |
| tab.isPreview && | |
| isEditorTabContentType(tab.contentType) | |
| ) | |
| const previewTab = tabsForWorktree.find( | |
| (candidate) => | |
| (!pinnedGroupId || candidate.groupId === pinnedGroupId) && | |
| candidate.isPreview && | |
| isEditorTabContentType(candidate.contentType) && | |
| !tabsForWorktree.some( | |
| (tab) => | |
| tab.id !== candidate.id && | |
| tab.entityId === candidate.entityId && | |
| isEditorTabContentType(tab.contentType) | |
| ) | |
| ) |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This PR makes unpinned editor/diff preview reuse worktree-scoped instead of group-scoped, so a preview parked in a neighboring split is recycled rather than a second preview opening over the focused terminal (the "small fix" half of #11839).
resolveReplaceablePreviewSlot— replacesgetReplaceablePreviewFileId. Unpinned opens find the parked preview tab anywhere in the worktree and return itsindexplus aretargetGroupId; pinned opens (pinnedGroupIdset) keep the old group scoping, and the shared-entity guard is preserved.openWorkspaceEditorItem— trailing positional args become anopenoptions object (isPreview/targetGroupId/pinnedGroupId). Unpinned previews re-activate an existing tab for the same entity wherever it lives before falling through to group resolution/creation.- Call-site migration —
open-file-action,open-file-apply,open-unstaged-diff,open-history-diff,open-conflict-file,open-conflict-review, andmarkdown-preview-actionsall threadpinnedGroupIdthrough and reuse the shared slot helper. No stale callers of the old signature remain. - Tests — new
editor-parked-preview-reuse.test.ts(4 real slice-integration tests) covers cross-group recycling, file-explorer preview opens, same-file re-activation, and pinned-group scoping; assertions are exact enough to catch the original bug.
I verified the change end-to-end against the slice implementation and ran the affected test families (331 tests green, including the existing shared-preview-diff and Source Control preview-open suites). One informational note for scope tracking: the "only one preview tab per worktree" acceptance criterion from #11839 is intentionally not fully enforced here — two pinned previews in different groups can still coexist — which is consistent with this being the scoped small fix.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Fixed the two reproduced regressions in 0820839. My earlier readiness assessment missed these cases and is superseded by this correction.
Added four regression tests covering focused-group preference, promoted editor backing state, promoted diff backing state, and permanent-file side-by-side opening. The original parked-preview and explicit-target tests continue to pass. Validation: 106 focused editor tests, web typecheck, targeted oxlint, and diff checks pass. The correction is also incorporated into stacked PR #19182, where 51 focused editor/Source Control/layout tests and web typecheck pass. Fresh rendered Electron checks were not run for this correction. |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This delta hardens the base fix against two edge cases the first pass left open: it prefers the focused group's parked preview when several exist, and it stops a stale OpenFile.isPreview (left behind by tab-layer promotion) from overwriting a permanent tab's backing file.
resolveReplaceablePreviewSlotgains a resolved-group argument — unpinned opens now prefer the preview parked in the resolved (focused) group before falling back to the first candidate, so recycling tracks focus rather than insertion order. Pinned opens are unchanged.openWorkspaceEditorItemreactivation is preview-only — theexistingAnywherescan now requirestab.isPreview, so an unpinned open of an already-permanent entity reopens it locally instead of stealing focus from the other group.- Headless fallback is gated tighter — the
openFilesscan now only runs when there are no pins, no resolved group, and no tabs, preventing a promoted tab's staleisPreviewfrom being recycled out from under it. - Four new regression tests cover focused-group preference, promoted-tab backing-file preservation, local permanent reopen, and promoted-diff preservation.
One informational note for scope tracking: the new guard works around a pre-existing asymmetry rather than fixing it — activateTab promotes a preview tab to permanent at the tab layer but leaves OpenFile.isPreview stale (the new test at editor-parked-preview-reuse.test.ts:220 documents this). Other readers of OpenFile.isPreview could still observe a permanent tab as a preview; worth a follow-up but out of scope for this small fix.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
The CI red here is an unrelated flake, not this change:
A re-run of the failed job should clear it. Thanks again for the clean split and keeping the authorship/credit. |

ELI5
After focusing a terminal, clicking another changed file now updates the preview parked in a neighboring split instead of opening a second preview over the terminal.
What Changed / Why
Part 1 of the split of #11866. Unpinned editor and diff previews reuse the existing preview across tab groups within the workspace. Explicitly targeted opens keep group scoping, and previews sharing an editor entity remain protected. Includes the editor open-call contract and parked-preview regression tests.
The optional Source Control side-split setting is isolated in #19182, based on this branch. Merge this fix first, then retarget part 2 to
main.Original implementation by Dan Cieslak (@dcieslak19973) in #11866; his Git commit authorship is preserved. This PR extracts and rebases his fix onto current
main.Linked Issue
Addresses the parked-preview bug in #11839. Split from #11866.
Visual Proof
These are the original PR’s Electron/CDP captures, reused as historical evidence; rendered validation was not rerun on this split head.
Before the click: preview parked beside the focused terminal.
After clicking another changed file: the parked preview is reused.
Testing
Review
Checked explicit group scoping, shared preview entities, per-file cleanup, and workspace isolation. No new platform shortcuts, filesystem operations, Git commands, execution-host assumptions, or remote wire fields. Existing folder/SSH editor paths remain in use.
Agent skill upstream boundary