Skip to content

Commit 8f1e089

Browse files
committed
Improve autoselect and scroll into view
1 parent d5cdf14 commit 8f1e089

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

apps/desktop/src/components/ChangedFiles.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,16 @@
5454
let listMode: 'list' | 'tree' = $state('tree');
5555
5656
$effect(() => {
57-
if (autoselect && selectionId) {
57+
if (selectionId) {
58+
const selection = idSelection.getById(selectionId);
5859
// Prevent effect from running when `changes` updates.
5960
untrack(() => {
60-
idSelection.set(changes[0]!.path, selectionId, 0);
61+
if (autoselect && selection.entries.size === 0) {
62+
const firstChange = changes.at(0);
63+
if (firstChange) {
64+
idSelection.set(firstChange.path, selectionId, 0);
65+
}
66+
}
6167
});
6268
}
6369
});

apps/desktop/src/components/FileListItemWrapper.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
let timeoutId: any;
117117
118118
$effect(() => {
119-
if (selected && draggableEl) {
119+
if (selected && draggableEl && active) {
120120
if (timeoutId) {
121121
clearTimeout(timeoutId);
122122
}

apps/desktop/src/components/StackView.svelte

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,23 @@
111111
const branchName = $derived(selection.current?.branchName);
112112
const upstream = $derived(selection.current?.upstream);
113113
114-
const selectedLastAdded = $derived.by(() => {
114+
const activeSelectionId: SelectionId | undefined = $derived.by(() => {
115115
if (commitId) {
116-
return idSelection.getById({ type: 'commit', commitId, stackId: stack.id }).lastAdded;
116+
return { type: 'commit', commitId, stackId: stack.id };
117117
} else if (branchName) {
118-
return idSelection.getById({ type: 'branch', stackId: stack.id, branchName }).lastAdded;
118+
return { type: 'branch', stackId: stack.id, branchName };
119119
}
120120
});
121121
122-
const selectedKey = $derived(
123-
$selectedLastAdded?.key ? readKey($selectedLastAdded.key) : undefined
124-
);
122+
const activeLastAdded = $derived.by(() => {
123+
if (activeSelectionId) {
124+
return idSelection.getById(activeSelectionId).lastAdded;
125+
}
126+
});
125127
126-
const previewKey = $derived(assignedKey || selectedKey);
128+
const selectedFile = $derived($activeLastAdded?.key ? readKey($activeLastAdded.key) : undefined);
129+
130+
const previewKey = $derived(assignedKey || selectedFile);
127131
const previewChangeResult = $derived(
128132
previewKey ? idSelection.changeByKey(projectId, previewKey) : undefined
129133
);
@@ -282,8 +286,8 @@
282286
stackId={stack.id}
283287
{projectId}
284288
{branchName}
285-
active={selectedKey?.type === 'branch' &&
286-
selectedKey.branchName === branchName &&
289+
active={selectedFile?.type === 'branch' &&
290+
selectedFile.branchName === branchName &&
287291
focusedStackId === stack.id}
288292
scrollToType="details"
289293
scrollToId={stack.id}
@@ -304,7 +308,7 @@
304308
upstream: !!upstream
305309
}}
306310
draggableFiles
307-
active={selectedKey?.type === 'commit' && focusedStackId === stack.id}
311+
active={selectedFile?.type === 'commit' && focusedStackId === stack.id}
308312
scrollToType="details"
309313
scrollToId={stack.id}
310314
bind:clientHeight={actualDetailsHeight}
@@ -314,7 +318,7 @@
314318
{/snippet}
315319

316320
{#snippet commitChangedFiles(commitId: string)}
317-
{@const active = selectedKey?.type === 'commit' && focusedStackId === stack.id}
321+
{@const active = activeSelectionId?.type === 'commit' && focusedStackId === stack.id}
318322
{@const changesResult = stackService.commitChanges(projectId, commitId)}
319323
<ReduxResult {projectId} stackId={stack.id} result={changesResult.current}>
320324
{#snippet children(changes, { projectId, stackId })}
@@ -349,7 +353,7 @@
349353
{/snippet}
350354

351355
{#snippet branchChangedFiles(branchName: string)}
352-
{@const active = selectedKey?.type === 'branch' && focusedStackId === stack.id}
356+
{@const active = activeSelectionId?.type === 'branch' && focusedStackId === stack.id}
353357
{@const changesResult = stackService.branchChanges({
354358
projectId,
355359
stackId: stack.id,
@@ -362,6 +366,7 @@
362366
{projectId}
363367
{stackId}
364368
draggableFiles
369+
autoselect
365370
selectionId={{ type: 'branch', stackId: stack.id, branchName }}
366371
noshrink={!!previewKey}
367372
ontoggle={() => {
@@ -513,7 +518,7 @@
513518
</ReduxResult>
514519
</div>
515520

516-
{#if commitId || branchName || assignedKey || selectedKey}
521+
{#if commitId || branchName || assignedKey || selectedFile}
517522
<div
518523
class="combined-view"
519524
bind:this={compactDiv}
@@ -529,7 +534,7 @@
529534
{@render branchChangedFiles(branchName)}
530535
{/if}
531536

532-
{#if assignedKey || selectedKey}
537+
{#if assignedKey || selectedFile}
533538
<ReduxResult {projectId} result={previewChangeResult?.current}>
534539
{#snippet children(previewChange)}
535540
{@const diffResult = diffService.getDiff(projectId, previewChange)}
@@ -539,7 +544,7 @@
539544
<ConfigurableScrollableContainer zIndex="var(--z-lifted)">
540545
{@render assignedChangePreview(assignedKey.stackId)}
541546
</ConfigurableScrollableContainer>
542-
{:else if selectedKey}
547+
{:else if selectedFile}
543548
<Drawer bottomBorder>
544549
{#snippet header()}
545550
<FileViewHeader
@@ -555,7 +560,7 @@
555560
: undefined}
556561
/>
557562
{/snippet}
558-
{@render otherChangePreview(selectedKey)}
563+
{@render otherChangePreview(selectedFile)}
559564
</Drawer>
560565
{/if}
561566
{/snippet}

0 commit comments

Comments
 (0)