Skip to content

Commit 6de7eb1

Browse files
committed
Use replaceBranchInStackSelection in stackService
Update stackService to enhance branch name replacement logic by using replaceBranchInStackSelection helper when updating stack selection state. This avoids unnecessary double wrapping and ensures consistency with exclusive action branch name updates.
1 parent eae627c commit 6de7eb1

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-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(

0 commit comments

Comments
 (0)