Skip to content

Commit 874afac

Browse files
committed
Offset horz scroll when opening unassigned change preview
1 parent ba412ef commit 874afac

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

apps/desktop/src/components/MultiStackView.svelte

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import { inject } from '@gitbutler/core/context';
2222
import { persisted } from '@gitbutler/shared/persisted';
2323
import { DRAG_STATE_SERVICE } from '@gitbutler/ui/drag/dragStateService.svelte';
24+
import { resizeObserver } from '@gitbutler/ui/utils/resizeObserver';
2425
import { isDefined } from '@gitbutler/ui/utils/typeguards';
2526
import { flip } from 'svelte/animate';
2627
import type { Stack } from '$lib/stacks/stack';
@@ -55,6 +56,9 @@
5556
let visibleIndexes = $state<number[]>([0]);
5657
let isCreateNewVisible = $state<boolean>(false);
5758
59+
/** Used to offset content shift from opening an unassigned change preview. */
60+
let lastWidth = $state<number>();
61+
5862
const projectState = $derived(uiState.project(projectId));
5963
const exclusiveAction = $derived(projectState.exclusiveAction.current);
6064
const isCommitting = $derived(exclusiveAction?.type === 'commit');
@@ -154,6 +158,15 @@
154158
.filter(isDefined)
155159
});
156160
}}
161+
use:resizeObserver={(data) => {
162+
if (lastWidth && lanesScrollableEl) {
163+
const diff = lastWidth - lanesScrollableEl.clientWidth;
164+
if (Math.abs(diff) > 100) {
165+
lanesScrollableEl.scrollBy({ left: diff });
166+
}
167+
}
168+
lastWidth = data.frame.width;
169+
}}
157170
>
158171
<div class="lanes-scrollable">
159172
<StackDraft {projectId} visible={isDraftStackVisible} />

0 commit comments

Comments
 (0)