1
1
import { ChangeDropData , HunkDropDataV3 } from '$lib/dragging/draggables' ;
2
2
import { type DiffService } from '$lib/hunks/diffService.svelte' ;
3
3
import type { DropzoneHandler } from '$lib/dragging/handler' ;
4
+ import type { IdSelection } from '$lib/selection/idSelection.svelte' ;
4
5
import type { UncommittedService } from '$lib/selection/uncommittedService.svelte' ;
5
6
6
7
export class AssignmentDropHandler implements DropzoneHandler {
7
8
constructor (
8
9
private readonly projectId : string ,
9
10
private readonly diffService : DiffService ,
10
11
private readonly uncommittedService : UncommittedService ,
11
- private readonly stackId : string | null
12
+ private readonly stackId : string | null ,
13
+ private readonly idSelection : IdSelection
12
14
) { }
13
15
14
16
accepts ( data : unknown ) {
@@ -28,6 +30,7 @@ export class AssignmentDropHandler implements DropzoneHandler {
28
30
29
31
async ondrop ( data : ChangeDropData | HunkDropDataV3 ) {
30
32
if ( data instanceof ChangeDropData ) {
33
+ // A whole file.
31
34
const changes = await data . treeChanges ( ) ;
32
35
const assignments = changes
33
36
. flatMap ( ( c ) => this . uncommittedService . getAssignmentsByPath ( data . stackId , c . path ) )
@@ -36,16 +39,28 @@ export class AssignmentDropHandler implements DropzoneHandler {
36
39
projectId : this . projectId ,
37
40
assignments
38
41
} ) ;
42
+
43
+ // If files are coming from the uncommitted changes
44
+ this . idSelection . remove ( data . change . path , data . selectionId ) ;
39
45
} else {
40
46
const assignment = this . uncommittedService . getAssignmentByHeader (
41
47
data . stackId ,
42
48
data . change . path ,
43
49
data . hunk
44
50
) . current ! ;
51
+ const allAssignments = this . uncommittedService . getAssignmentsByPath (
52
+ data . stackId ,
53
+ data . change . path
54
+ ) ;
45
55
await this . diffService . assignHunk ( {
46
56
projectId : this . projectId ,
47
57
assignments : [ { ...assignment , stackId : this . stackId } ]
48
58
} ) ;
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
+ }
49
64
}
50
65
}
51
66
}
0 commit comments