Skip to content

Commit 1d28b86

Browse files
Merge pull request #9063 from gitbutlerapp/fix-drawer-not-closing-after-assignment
Fix drawer not closign after asignment
2 parents 5552723 + 32d4960 commit 1d28b86

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

apps/desktop/src/components/v3/WorktreeChanges.svelte

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import { focusable } from '$lib/focus/focusable.svelte';
1212
import { DiffService } from '$lib/hunks/diffService.svelte';
1313
import { AssignmentDropHandler } from '$lib/hunks/dropHandler';
14+
import { IdSelection } from '$lib/selection/idSelection.svelte';
1415
import { UncommittedService } from '$lib/selection/uncommittedService.svelte';
1516
import { StackService } from '$lib/stacks/stackService.svelte';
1617
import { UiState } from '$lib/state/uiState.svelte';
@@ -49,11 +50,12 @@
4950
onselect
5051
}: Props = $props();
5152
52-
const [uiState, stackService, diffService, uncommittedService] = inject(
53+
const [uiState, stackService, diffService, uncommittedService, idSelection] = inject(
5354
UiState,
5455
StackService,
5556
DiffService,
56-
UncommittedService
57+
UncommittedService,
58+
IdSelection
5759
);
5860
5961
const uncommitDzHandler = $derived(
@@ -77,7 +79,13 @@
7779
let scrollTopIsVisible = $state(true);
7880
7981
const assignmentDZHandler = $derived(
80-
new AssignmentDropHandler(projectId, diffService, uncommittedService, stackId || null)
82+
new AssignmentDropHandler(
83+
projectId,
84+
diffService,
85+
uncommittedService,
86+
stackId || null,
87+
idSelection
88+
)
8189
);
8290
8391
function getDropzoneLabel(handler: DropzoneHandler | undefined): string {

apps/desktop/src/lib/hunks/dropHandler.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { ChangeDropData, HunkDropDataV3 } from '$lib/dragging/draggables';
22
import { type DiffService } from '$lib/hunks/diffService.svelte';
33
import type { DropzoneHandler } from '$lib/dragging/handler';
4+
import type { IdSelection } from '$lib/selection/idSelection.svelte';
45
import type { UncommittedService } from '$lib/selection/uncommittedService.svelte';
56

67
export class AssignmentDropHandler implements DropzoneHandler {
78
constructor(
89
private readonly projectId: string,
910
private readonly diffService: DiffService,
1011
private readonly uncommittedService: UncommittedService,
11-
private readonly stackId: string | null
12+
private readonly stackId: string | null,
13+
private readonly idSelection: IdSelection
1214
) {}
1315

1416
accepts(data: unknown) {
@@ -28,6 +30,7 @@ export class AssignmentDropHandler implements DropzoneHandler {
2830

2931
async ondrop(data: ChangeDropData | HunkDropDataV3) {
3032
if (data instanceof ChangeDropData) {
33+
// A whole file.
3134
const changes = await data.treeChanges();
3235
const assignments = changes
3336
.flatMap((c) => this.uncommittedService.getAssignmentsByPath(data.stackId, c.path))
@@ -36,16 +39,28 @@ export class AssignmentDropHandler implements DropzoneHandler {
3639
projectId: this.projectId,
3740
assignments
3841
});
42+
43+
// If files are coming from the uncommitted changes
44+
this.idSelection.remove(data.change.path, data.selectionId);
3945
} else {
4046
const assignment = this.uncommittedService.getAssignmentByHeader(
4147
data.stackId,
4248
data.change.path,
4349
data.hunk
4450
).current!;
51+
const allAssignments = this.uncommittedService.getAssignmentsByPath(
52+
data.stackId,
53+
data.change.path
54+
);
4555
await this.diffService.assignHunk({
4656
projectId: this.projectId,
4757
assignments: [{ ...assignment, stackId: this.stackId }]
4858
});
59+
60+
// If we just moved the last assignment, remove the file from the selection.
61+
if (allAssignments.length === 1) {
62+
this.idSelection.remove(data.change.path, data.selectionId);
63+
}
4964
}
5065
}
5166
}

0 commit comments

Comments
 (0)