fix: preserve stack primary asset selection (#31380)

* fix: preserve stack primary asset selection

* test: select stacked assets by id

* chore: limit dart formatting changes

* fix: address stack viewer review feedback

* fix: align stack ordering with server

* fix: keep stack primary asset first

---------

Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>
(cherry picked from commit 5a5d7be11084969c3c00a294ce6c0527042f88e7)
This commit is contained in:
Kairui Liu
2026-10-27 23:12:13 +03:00
committed by Codex
parent 75a1d7c5c8
commit c482c1e53e
7 changed files with 41 additions and 10 deletions
@@ -291,16 +291,15 @@
if (!stack || !withStacked || assetViewerManager.isShowEditor) {
return;
}
const assets = stack.assets;
const currentIndex = assets.findIndex(({ id }) => id === asset.id);
const currentIndex = stack.assets.findIndex(({ id }) => id === asset.id);
if (currentIndex === -1) {
return;
}
const nextIndex = direction === 'previous' ? currentIndex - 1 : currentIndex + 1;
if (nextIndex < 0 || nextIndex >= assets.length) {
if (nextIndex < 0 || nextIndex >= stack.assets.length) {
return;
}
cursor.current = assets[nextIndex];
cursor.current = stack.assets[nextIndex];
};
/**
@@ -94,7 +94,9 @@
};
const handleStack = () => {
onStack(assets);
const selectedAssets = assets.filter(({ id }) => selectedAssetIds.has(id));
const unselectedAssets = assets.filter(({ id }) => !selectedAssetIds.has(id));
onStack([...selectedAssets, ...unselectedAssets]);
};
const assetCursor = $derived({