Skip to content

Commit a3a0b3f

Browse files
CopilotByron
andcommitted
Show diffs for all selected files instead of just the last one
Co-authored-by: Byron <[email protected]>
1 parent 74440a1 commit a3a0b3f

File tree

1 file changed

+47
-46
lines changed

1 file changed

+47
-46
lines changed

apps/desktop/src/components/SelectionView.svelte

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { isExecutableStatus } from '$lib/hunks/change';
77
import { DIFF_SERVICE } from '$lib/hunks/diffService.svelte';
88
import { FILE_SELECTION_MANAGER } from '$lib/selection/fileSelectionManager.svelte';
9-
import { readKey, type SelectionId } from '$lib/selection/key';
9+
import { type SelectionId } from '$lib/selection/key';
1010
import { inject } from '@gitbutler/core/context';
1111
1212
type Props = {
@@ -35,13 +35,11 @@
3535
const diffService = inject(DIFF_SERVICE);
3636
3737
const selection = $derived(selectionId ? idSelection.valuesReactive(selectionId) : undefined);
38-
const lastAdded = $derived(selectionId ? idSelection.getById(selectionId).lastAdded : undefined);
3938
40-
const selectedFile = $derived.by(() => {
41-
if (!selectionId || !selection) return;
42-
if (selection.current.length === 0) return;
43-
if (selection.current.length === 1 || !$lastAdded) return selection.current[0];
44-
return readKey($lastAdded.key);
39+
const selectedFiles = $derived.by(() => {
40+
if (!selectionId || !selection) return [];
41+
if (selection.current.length === 0) return [];
42+
return selection.current;
4543
});
4644
4745
const stackId = $derived(
@@ -52,49 +50,51 @@
5250
</script>
5351

5452
<div class="selection-view" data-testid={testId}>
55-
{#if selectedFile}
56-
{@const changeQuery = idSelection.changeByKey(projectId, selectedFile)}
57-
<ReduxResult {projectId} result={changeQuery.result}>
58-
{#snippet children(change)}
59-
{@const diffQuery = diffService.getDiff(projectId, change)}
60-
{@const isExecutable = isExecutableStatus(change.status)}
61-
<ReduxResult {projectId} result={diffQuery.result}>
62-
{#snippet children(diff, env)}
63-
<div
64-
class="selected-change-item"
65-
class:bottom-border={bottomBorder}
66-
data-remove-from-panning
67-
>
68-
{#if !diffOnly}
69-
<FileListItemWrapper
70-
selectionId={selectedFile}
53+
{#if selectedFiles.length > 0}
54+
{#each selectedFiles as selectedFile, index (selectedFile.path)}
55+
{@const changeQuery = idSelection.changeByKey(projectId, selectedFile)}
56+
<ReduxResult {projectId} result={changeQuery.result}>
57+
{#snippet children(change)}
58+
{@const diffQuery = diffService.getDiff(projectId, change)}
59+
{@const isExecutable = isExecutableStatus(change.status)}
60+
<ReduxResult {projectId} result={diffQuery.result}>
61+
{#snippet children(diff, env)}
62+
<div
63+
class="selected-change-item"
64+
class:bottom-border={bottomBorder || index < selectedFiles.length - 1}
65+
data-remove-from-panning
66+
>
67+
{#if !diffOnly}
68+
<FileListItemWrapper
69+
selectionId={selectedFile}
70+
projectId={env.projectId}
71+
{scrollContainer}
72+
{change}
73+
{diff}
74+
{draggable}
75+
isHeader
76+
executable={isExecutable}
77+
listMode="list"
78+
onCloseClick={onclose}
79+
/>
80+
{/if}
81+
<UnifiedDiffView
7182
projectId={env.projectId}
72-
{scrollContainer}
83+
{stackId}
84+
commitId={selectedFile.type === 'commit' ? selectedFile.commitId : undefined}
85+
{draggable}
7386
{change}
7487
{diff}
75-
{draggable}
76-
isHeader
77-
executable={isExecutable}
78-
listMode="list"
79-
onCloseClick={onclose}
88+
{selectable}
89+
selectionId={selectedFile}
90+
topPadding={diffOnly}
8091
/>
81-
{/if}
82-
<UnifiedDiffView
83-
projectId={env.projectId}
84-
{stackId}
85-
commitId={selectedFile.type === 'commit' ? selectedFile.commitId : undefined}
86-
{draggable}
87-
{change}
88-
{diff}
89-
{selectable}
90-
selectionId={selectedFile}
91-
topPadding={diffOnly}
92-
/>
93-
</div>
94-
{/snippet}
95-
</ReduxResult>
96-
{/snippet}
97-
</ReduxResult>
92+
</div>
93+
{/snippet}
94+
</ReduxResult>
95+
{/snippet}
96+
</ReduxResult>
97+
{/each}
9898
{:else}
9999
<FilePreviewPlaceholder />
100100
{/if}
@@ -104,6 +104,7 @@
104104
.selection-view {
105105
display: flex;
106106
flex-grow: 1;
107+
flex-direction: column;
107108
width: 100%;
108109
height: 100%;
109110
}

0 commit comments

Comments
 (0)