Skip to content

Commit 36f180b

Browse files
committed
15712: Add asset highlight using arrow keys.
1 parent cd40054 commit 36f180b

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

web/src/lib/components/assets/thumbnail/thumbnail.svelte

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
thumbnailWidth?: number | undefined;
4141
thumbnailHeight?: number | undefined;
4242
selected?: boolean;
43+
highlight?: boolean;
4344
selectionCandidate?: boolean;
4445
disabled?: boolean;
4546
readonly?: boolean;
@@ -72,6 +73,7 @@
7273
thumbnailWidth = undefined,
7374
thumbnailHeight = undefined,
7475
selected = false,
76+
highlight = false,
7577
selectionCandidate = false,
7678
disabled = false,
7779
readonly = false,
@@ -251,7 +253,7 @@
251253
{/if}
252254
<div class="absolute z-20 {className}" style:width="{width}px" style:height="{height}px">
253255
<!-- Select asset button -->
254-
{#if !readonly && (mouseOver || selected || selectionCandidate)}
256+
{#if !readonly && (mouseOver || selected || selectionCandidate || highlight)}
255257
<button
256258
type="button"
257259
onclick={onIconClickedHandler}

web/src/lib/components/photos-page/asset-date-group.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
onSelect={(asset) => assetSelectHandler(asset, dateGroup.assets, dateGroup.groupTitle)}
214214
onMouseEvent={() => assetMouseEventHandler(dateGroup.groupTitle, asset)}
215215
selected={assetInteraction.selectedAssets.has(asset) || $assetStore.albumAssets.has(asset.id)}
216+
highlight={assetInteraction.isHighlightAsset(asset)}
216217
selectionCandidate={assetInteraction.assetSelectionCandidates.has(asset)}
217218
disabled={$assetStore.albumAssets.has(asset.id)}
218219
thumbnailWidth={box.width}

web/src/lib/components/photos-page/asset-grid.svelte

+23
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,29 @@
774774
{ shortcut: { key: 'A', ctrl: true }, onShortcut: () => selectAllAssets($assetStore, assetInteraction) },
775775
{ shortcut: { key: 'PageDown' }, preventDefault: false, onShortcut: focusElement },
776776
{ shortcut: { key: 'PageUp' }, preventDefault: false, onShortcut: focusElement },
777+
{
778+
shortcut: { key: 'ArrowRight' },
779+
preventDefault: false,
780+
onShortcut: async () => {
781+
const currentHighlightAsset = assetInteraction.getHighlightAsset();
782+
const nextHighlightAsset =
783+
currentHighlightAsset === null
784+
? $assetStore.getFirstAsset()
785+
: await $assetStore.getNextAsset(currentHighlightAsset);
786+
assetInteraction.setHighlightAsset(nextHighlightAsset);
787+
},
788+
},
789+
{
790+
shortcut: { key: 'ArrowLeft' },
791+
preventDefault: false,
792+
onShortcut: async () => {
793+
const currentHighlightAsset = assetInteraction.getHighlightAsset();
794+
if (currentHighlightAsset !== null) {
795+
const previousHighlightAsset = await $assetStore.getPreviousAsset(currentHighlightAsset);
796+
assetInteraction.setHighlightAsset(previousHighlightAsset);
797+
}
798+
},
799+
},
777800
];
778801
779802
if (assetInteraction.selectionActive) {

web/src/lib/stores/asset-interaction.svelte.ts

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class AssetInteraction {
1414

1515
private user = fromStore<UserAdminResponseDto | undefined>(user);
1616
private userId = $derived(this.user.current?.id);
17+
private highlightAsset = $state<AssetResponseDto | null>(null);
1718

1819
isAllTrashed = $derived(this.selectedAssetsArray.every((asset) => asset.isTrashed));
1920
isAllArchived = $derived(this.selectedAssetsArray.every((asset) => asset.isArchived));
@@ -63,4 +64,16 @@ export class AssetInteraction {
6364
this.assetSelectionCandidates.clear();
6465
this.assetSelectionStart = null;
6566
}
67+
68+
isHighlightAsset(asset: AssetResponseDto) {
69+
return this.highlightAsset?.id === asset.id;
70+
}
71+
72+
setHighlightAsset(asset: AssetResponseDto | null) {
73+
this.highlightAsset = asset;
74+
}
75+
76+
getHighlightAsset() {
77+
return this.highlightAsset;
78+
}
6679
}

web/src/lib/stores/assets.store.ts

+7
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,13 @@ export class AssetStore {
836836
this.emit(true);
837837
}
838838

839+
getFirstAsset(): AssetResponseDto | null {
840+
if (this.buckets.length > 0 && this.buckets[0].assets.length > 0) {
841+
return this.buckets[0].assets[0];
842+
}
843+
return null;
844+
}
845+
839846
async getPreviousAsset(asset: AssetResponseDto): Promise<AssetResponseDto | null> {
840847
const info = await this.getBucketInfoForAsset(asset);
841848
if (!info) {

0 commit comments

Comments
 (0)