|  | 
| 6 | 6 | 	import { isExecutableStatus } from '$lib/hunks/change'; | 
| 7 | 7 | 	import { DIFF_SERVICE } from '$lib/hunks/diffService.svelte'; | 
| 8 | 8 | 	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'; | 
| 10 | 10 | 	import { inject } from '@gitbutler/core/context'; | 
| 11 | 11 | 
 | 
| 12 | 12 | 	type Props = { | 
|  | 
| 35 | 35 | 	const diffService = inject(DIFF_SERVICE); | 
| 36 | 36 | 
 | 
| 37 | 37 | 	const selection = $derived(selectionId ? idSelection.valuesReactive(selectionId) : undefined); | 
| 38 |  | -	const lastAdded = $derived(selectionId ? idSelection.getById(selectionId).lastAdded : undefined); | 
| 39 | 38 | 
 | 
| 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; | 
| 45 | 43 | 	}); | 
| 46 | 44 | 
 | 
| 47 | 45 | 	const stackId = $derived( | 
|  | 
| 52 | 50 | </script> | 
| 53 | 51 | 
 | 
| 54 | 52 | <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 | 
| 71 | 82 | 									projectId={env.projectId} | 
| 72 |  | -									{scrollContainer} | 
|  | 83 | +									{stackId} | 
|  | 84 | +									commitId={selectedFile.type === 'commit' ? selectedFile.commitId : undefined} | 
|  | 85 | +									{draggable} | 
| 73 | 86 | 									{change} | 
| 74 | 87 | 									{diff} | 
| 75 |  | -									{draggable} | 
| 76 |  | -									isHeader | 
| 77 |  | -									executable={isExecutable} | 
| 78 |  | -									listMode="list" | 
| 79 |  | -									onCloseClick={onclose} | 
|  | 88 | +									{selectable} | 
|  | 89 | +									selectionId={selectedFile} | 
|  | 90 | +									topPadding={diffOnly} | 
| 80 | 91 | 								/> | 
| 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} | 
| 98 | 98 | 	{:else} | 
| 99 | 99 | 		<FilePreviewPlaceholder /> | 
| 100 | 100 | 	{/if} | 
|  | 
| 104 | 104 | 	.selection-view { | 
| 105 | 105 | 		display: flex; | 
| 106 | 106 | 		flex-grow: 1; | 
|  | 107 | +		flex-direction: column; | 
| 107 | 108 | 		width: 100%; | 
| 108 | 109 | 		height: 100%; | 
| 109 | 110 | 	} | 
|  | 
0 commit comments