Skip to content

Commit 7d296ba

Browse files
authored
Merge pull request #9497 from gitbutlerapp/branch-selection-fix
Branch selection fix
2 parents 38f675f + 6de7eb1 commit 7d296ba

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
providesList,
1313
ReduxTag
1414
} from '$lib/state/tags';
15-
import { replaceBranchInExclusiveAction, type UiState } from '$lib/state/uiState.svelte';
15+
import {
16+
replaceBranchInExclusiveAction,
17+
replaceBranchInStackSelection,
18+
type UiState
19+
} from '$lib/state/uiState.svelte';
1620
import { isDefined } from '@gitbutler/ui/utils/typeguards';
1721
import {
1822
createEntityAdapter,
@@ -615,12 +619,16 @@ export class StackService {
615619
const stackState = this.uiState.stack(args.stackId);
616620
const projectState = this.uiState.project(args.projectId);
617621
const exclusiveAction = projectState.exclusiveAction.current;
618-
const previousSelection = stackState.selection.current ?? {};
622+
const previousSelection = stackState.selection.current;
619623

620-
stackState.selection.set({
621-
...previousSelection,
622-
branchName: args.newName
623-
});
624+
if (previousSelection) {
625+
const updatedSelection = replaceBranchInStackSelection(
626+
previousSelection,
627+
args.branchName,
628+
args.newName
629+
);
630+
stackState.selection.set(updatedSelection);
631+
}
624632

625633
if (exclusiveAction) {
626634
const updatedExclusiveAction = replaceBranchInExclusiveAction(

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,14 @@ export function replaceBranchInExclusiveAction(
267267
return action;
268268
}
269269
}
270+
271+
export function replaceBranchInStackSelection(
272+
selection: StackSelection,
273+
oldBranchName: string,
274+
branchName: string
275+
): StackSelection {
276+
if (selection.branchName === oldBranchName) {
277+
return { ...selection, branchName };
278+
}
279+
return selection;
280+
}

0 commit comments

Comments
 (0)