|
14 | 14 | import { focusable } from '$lib/focus/focusable.svelte';
|
15 | 15 | import { DiffService } from '$lib/hunks/diffService.svelte';
|
16 | 16 | import { AssignmentDropHandler } from '$lib/hunks/dropHandler';
|
17 |
| - import { ChangeSelectionService } from '$lib/selection/changeSelection.svelte'; |
| 17 | + import { |
| 18 | + ChangeSelectionService, |
| 19 | + selectForStartingCommit |
| 20 | + } from '$lib/selection/changeSelection.svelte'; |
18 | 21 | import { IdSelection } from '$lib/selection/idSelection.svelte';
|
19 | 22 | import { StackService } from '$lib/stacks/stackService.svelte';
|
20 | 23 | import { UiState } from '$lib/state/uiState.svelte';
|
21 | 24 | import { TestId } from '$lib/testing/testIds';
|
22 | 25 | import { WorktreeService } from '$lib/worktree/worktreeService.svelte';
|
23 |
| - import { getContext, inject } from '@gitbutler/shared/context'; |
| 26 | + import { inject } from '@gitbutler/shared/context'; |
24 | 27 | import Badge from '@gitbutler/ui/Badge.svelte';
|
25 | 28 | import Button from '@gitbutler/ui/Button.svelte';
|
26 | 29 | import { stickyHeader } from '@gitbutler/ui/utils/stickyHeader';
|
|
35 | 38 |
|
36 | 39 | let { projectId, stackId, active }: Props = $props();
|
37 | 40 |
|
38 |
| - const [changeSelection, worktreeService, uiState, stackService, idSelection] = inject( |
39 |
| - ChangeSelectionService, |
40 |
| - WorktreeService, |
41 |
| - UiState, |
42 |
| - StackService, |
43 |
| - IdSelection |
44 |
| - ); |
| 41 | + const [changeSelection, worktreeService, uiState, stackService, idSelection, diffService] = |
| 42 | + inject( |
| 43 | + ChangeSelectionService, |
| 44 | + WorktreeService, |
| 45 | + UiState, |
| 46 | + StackService, |
| 47 | + IdSelection, |
| 48 | + DiffService |
| 49 | + ); |
45 | 50 |
|
46 | 51 | const uncommitDzHandler = $derived(new UncommitDzHandler(projectId, stackService, uiState));
|
47 | 52 |
|
|
58 | 63 | const changesResult = $derived(worktreeService.getChanges(projectId));
|
59 | 64 | const affectedPaths = $derived(changesResult.current.data?.map((c) => c.path));
|
60 | 65 |
|
| 66 | + const changesKeyResult = $derived(worktreeService.getChangesKey(projectId)); |
| 67 | + const hunkAssignments = $derived( |
| 68 | + changesKeyResult.current |
| 69 | + ? diffService.hunkAssignments(projectId, changesKeyResult.current) |
| 70 | + : undefined |
| 71 | + ); |
| 72 | +
|
61 | 73 | // TODO: Make this go away.
|
62 | 74 | createCommitStore(undefined);
|
63 | 75 |
|
|
76 | 88 | let listMode: 'list' | 'tree' = $state('list');
|
77 | 89 |
|
78 | 90 | function startCommit() {
|
79 |
| - // TODO: Implement "Select the right stuff" |
| 91 | + if (changesResult.current?.data && hunkAssignments?.current?.data) { |
| 92 | + selectForStartingCommit( |
| 93 | + stackId, |
| 94 | + changesResult.current.data, |
| 95 | + hunkAssignments.current.data, |
| 96 | + changeSelection.list().current, |
| 97 | + changeSelection |
| 98 | + ); |
| 99 | + } |
| 100 | +
|
80 | 101 | projectState.drawerPage.set('new-commit');
|
81 | 102 | if (defaultBranchName) {
|
82 | 103 | stackState?.selection.set({ branchName: defaultBranchName });
|
|
85 | 106 |
|
86 | 107 | let listHeaderHeight = $state(0);
|
87 | 108 | let listFooterHeight = $state(0);
|
88 |
| -
|
89 |
| - const diffService = getContext(DiffService); |
90 |
| -
|
91 |
| - const changesKeyResult = $derived(worktreeService.getChangesKey(projectId)); |
92 |
| - const hunkAssignments = $derived( |
93 |
| - changesKeyResult.current |
94 |
| - ? diffService.hunkAssignments(projectId, changesKeyResult.current) |
95 |
| - : undefined |
96 |
| - ); |
97 | 109 | const assignmentDZHandler = $derived(
|
98 | 110 | hunkAssignments?.current?.data
|
99 | 111 | ? new AssignmentDropHandler(projectId, diffService, hunkAssignments.current.data, {
|
|
0 commit comments