fix(web): keyboard shortcut handling (#7946)

* fix(web): keyboard shortcut handling

* drop executeShortcuts in favor of action

* fix merge

---------

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
Michel Heusschen
2024-03-15 00:16:55 +01:00
committed by GitHub
parent 12fb90c232
commit eed8e6b67a
14 changed files with 197 additions and 268 deletions
+12 -20
View File
@@ -20,7 +20,7 @@
import { AppRoute, QueryParameter } from '$lib/constants';
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
import { preventRaceConditionSearchBar } from '$lib/stores/search.store';
import { shouldIgnoreShortcut } from '$lib/utils/shortcut';
import { shortcut } from '$lib/utils/shortcut';
import {
type AssetResponseDto,
searchSmart,
@@ -52,27 +52,19 @@
let searchResultAssets: AssetResponseDto[] = [];
let isLoading = true;
const onKeyboardPress = (event: KeyboardEvent) => handleKeyboardPress(event);
const handleKeyboardPress = async (event: KeyboardEvent) => {
if (shouldIgnoreShortcut(event)) {
const onEscape = () => {
if ($showAssetViewer) {
return;
}
if (!$showAssetViewer) {
switch (event.key) {
case 'Escape': {
if (isMultiSelectionMode) {
selectedAssets = new Set();
return;
}
if (!$preventRaceConditionSearchBar) {
await goto(previousRoute);
}
$preventRaceConditionSearchBar = false;
return;
}
}
if (isMultiSelectionMode) {
selectedAssets = new Set();
return;
}
if (!$preventRaceConditionSearchBar) {
handlePromiseError(goto(previousRoute));
}
$preventRaceConditionSearchBar = false;
};
afterNavigate(({ from }) => {
@@ -201,7 +193,7 @@
}
</script>
<svelte:document on:keydown={onKeyboardPress} />
<svelte:window use:shortcut={{ shortcut: { key: 'Escape' }, onShortcut: onEscape }} />
<section>
{#if isMultiSelectionMode}