Skip to content

Commit 68f9ea7

Browse files
authored
Merge pull request #10496 from gitbutlerapp/persist-preview-open-ui-state
UI state: Persist preview open
2 parents 106109a + fca1e5a commit 68f9ea7

File tree

12 files changed

+48
-50
lines changed

12 files changed

+48
-50
lines changed

apps/desktop/src/components/BranchCommitList.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
if (currentSelection?.commitId === commitId && currentSelection?.branchName === branchName) {
112112
laneState.selection.set(undefined);
113113
} else {
114-
laneState.selection.set({ branchName, commitId, upstream });
114+
laneState.selection.set({ branchName, commitId, upstream, previewOpen: true });
115115
}
116116
projectState.stackId.set(stackId);
117117
onselect?.();
@@ -330,7 +330,10 @@
330330
stackId,
331331
$runHooks,
332332
dzCommit,
333-
(newId) => uiState.lane(stackId).selection.set({ branchName, commitId: newId }),
333+
(newId) => {
334+
const previewOpen = selection.current?.previewOpen ?? false;
335+
uiState.lane(stackId).selection.set({ branchName, commitId: newId, previewOpen });
336+
},
334337
uiState
335338
)
336339
: undefined}

apps/desktop/src/components/BranchList.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
}
7575
7676
function startEditingCommitMessage(branchName: string, commitId: string) {
77-
laneState.selection.set({ branchName, commitId });
77+
laneState.selection.set({ branchName, commitId, previewOpen: true });
7878
projectState.exclusiveAction.set({
7979
type: 'edit-commit-message',
8080
stackId,
@@ -110,7 +110,7 @@
110110
if (selectedCommit && selectedCommit.result.status === QueryStatus.rejected) {
111111
const branchName = selection.current?.branchName;
112112
if (branchName) {
113-
selection.set({ branchName, commitId: undefined });
113+
selection.set({ branchName, commitId: undefined, previewOpen: false });
114114
}
115115
}
116116
});
@@ -214,7 +214,7 @@
214214
if (currentSelection?.branchName === branchName && !currentSelection?.commitId) {
215215
uiState.lane(laneId).selection.set(undefined);
216216
} else {
217-
uiState.lane(laneId).selection.set({ branchName });
217+
uiState.lane(laneId).selection.set({ branchName, previewOpen: true });
218218
}
219219
onselect?.();
220220
}}

apps/desktop/src/components/BranchView.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@
161161
onclick={() => {
162162
// Open commit preview by setting selection
163163
const laneState = uiState.lane(laneId);
164-
laneState.selection.set({ branchName, commitId: commit.id });
164+
laneState.selection.set({
165+
branchName,
166+
commitId: commit.id,
167+
previewOpen: true
168+
});
165169
}}
166170
/>
167171
{/each}

apps/desktop/src/components/CommitView.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@
117117
message: commitMessage
118118
});
119119
120-
uiState.lane(ensureValue(stackId)).selection.set({ branchName, commitId: newCommitId });
120+
uiState
121+
.lane(ensureValue(stackId))
122+
.selection.set({ branchName, commitId: newCommitId, previewOpen: true });
121123
setMode('view');
122124
}
123125

apps/desktop/src/components/FeedItemKind.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
const laneState = uiState.lane(stackId);
3434
laneState.selection.set({
3535
branchName,
36-
commitId
36+
commitId,
37+
previewOpen: true
3738
});
3839
projectState.stackId.set(stackId);
3940
}
@@ -42,7 +43,8 @@
4243
const projectState = uiState.project(projectId);
4344
const laneState = uiState.lane(stackId);
4445
laneState.selection.set({
45-
branchName
46+
branchName,
47+
previewOpen: true
4648
});
4749
projectState.stackId.set(stackId);
4850
}

apps/desktop/src/components/FileContextMenu.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@
177177
idSelection.removeMany(selectedFiles);
178178
179179
if (newCommitId && branchName) {
180+
const previewOpen = uiState.lane(stackId).selection.current?.previewOpen ?? false;
180181
// Update the selection to the new commit
181-
uiState.lane(stackId).selection.set({ branchName, commitId: newCommitId });
182+
uiState.lane(stackId).selection.set({ branchName, commitId: newCommitId, previewOpen });
182183
}
183184
contextMenu.close();
184185
}

apps/desktop/src/components/StackView.svelte

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
6060
let lanesSrollableEl = $state<HTMLDivElement>();
6161
62-
let isDetailsViewForcesClosed = $state(false);
63-
6462
const stackService = inject(STACK_SERVICE);
6563
const diffService = inject(DIFF_SERVICE);
6664
const uncommittedService = inject(UNCOMMITTED_SERVICE);
@@ -106,6 +104,7 @@
106104
const commitId = $derived(selection.current?.commitId);
107105
const branchName = $derived(selection.current?.branchName);
108106
const upstream = $derived(selection.current?.upstream);
107+
const previewOpen = $derived(selection.current?.previewOpen);
109108
110109
const activeSelectionId: SelectionId | undefined = $derived.by(() => {
111110
if (commitId) {
@@ -232,8 +231,10 @@
232231
}
233232
234233
function onclosePreviewOnly() {
235-
// Close the details view but keep the selection intact
236-
isDetailsViewForcesClosed = true;
234+
const source = selection.current;
235+
if (source) {
236+
selection.set({ ...source, previewOpen: false });
237+
}
237238
}
238239
239240
const startCommitVisible = $derived(uncommittedService.startCommitVisible(stackId));
@@ -258,32 +259,9 @@
258259
}
259260
260261
let isDetailsViewOpen = $derived(
261-
!!(branchName || commitId || assignedKey || selectedFile) && !isDetailsViewForcesClosed
262+
(!!(branchName || commitId || selectedFile) && previewOpen) || !!assignedKey
262263
);
263264
264-
// Track the current selection to detect when it changes
265-
let previousSelection = $state<{ branchName?: string; commitId?: string }>({});
266-
267-
// Reset the forced closed state when selection changes to a different branch/commit
268-
$effect(() => {
269-
const currentSelection = { branchName, commitId };
270-
271-
// Check if selection actually changed
272-
if (
273-
currentSelection.branchName !== previousSelection.branchName ||
274-
currentSelection.commitId !== previousSelection.commitId
275-
) {
276-
// Selection changed, allow details view to open again
277-
isDetailsViewForcesClosed = false;
278-
previousSelection = { ...currentSelection };
279-
280-
// Clear file selections from the previous context to allow auto-selection
281-
// to work properly for the new context
282-
if (activeSelectionId) {
283-
idSelection.clear(activeSelectionId);
284-
}
285-
}
286-
});
287265
const DETAILS_RIGHT_PADDING_REM = 1.125;
288266
289267
// Function to update CSS custom property for details view width

apps/desktop/src/lib/stacks/macros.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export default class StackMacros {
4040
if (outcome.newCommit) {
4141
this.uiState.lane(stack.id).selection.set({
4242
branchName,
43-
commitId: outcome.newCommit
43+
commitId: outcome.newCommit,
44+
previewOpen: true
4445
});
4546

4647
this.uiState.project(this.projectId).stackId.set(stack.id);
@@ -116,9 +117,12 @@ export default class StackMacros {
116117
throw new Error('No new commit id found for the moved changes');
117118
}
118119

120+
const previewOpen =
121+
this.uiState.lane(destinationStackId).selection.current?.previewOpen ?? false;
119122
this.uiState.lane(destinationStackId).selection.set({
120123
branchName,
121-
commitId: newCommitId
124+
commitId: newCommitId,
125+
previewOpen
122126
});
123127
this.uiState.project(this.projectId).stackId.set(destinationStackId);
124128
}

apps/desktop/src/lib/stacks/stackService.svelte.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,10 @@ export class StackService {
726726
},
727727
onError: (_, args) => {
728728
const state = this.uiState.lane(args.laneId);
729+
const previewOpen = state.selection.current?.previewOpen ?? false;
729730
state.selection.set({
730-
branchName: args.branchName
731+
branchName: args.branchName,
732+
previewOpen
731733
});
732734
}
733735
});

apps/desktop/src/lib/state/uiState.svelte.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type StackSelection = {
1919
branchName: string;
2020
commitId?: string;
2121
upstream?: boolean;
22+
previewOpen: boolean;
2223
};
2324

2425
export type NewCommitMessage = {
@@ -403,7 +404,8 @@ function updateStackSelection(uiState: UiState, stackId: string, details: StackD
403404
// If the selected commit is not in the branch, clear the commit selection
404405
if (!selection.upstream && !branchCommitIds.includes(selection.commitId)) {
405406
laneState.selection.set({
406-
branchName: selection.branchName
407+
branchName: selection.branchName,
408+
previewOpen: false
407409
});
408410

409411
return;
@@ -415,7 +417,8 @@ function updateStackSelection(uiState: UiState, stackId: string, details: StackD
415417
// If the selection is for an upstream commit and the commit is not in the upstream commits, clear the selection
416418
if (selection.upstream && !upstreamCommitIds.includes(selection.commitId)) {
417419
laneState.selection.set({
418-
branchName: selection.branchName
420+
branchName: selection.branchName,
421+
previewOpen: false
419422
});
420423

421424
return;

0 commit comments

Comments
 (0)