Use pre-existing shortcut methods

This commit is contained in:
Luc Mcgrady 2025-11-15 21:47:03 +00:00
parent f5cdf0f22f
commit acc672afcd
No known key found for this signature in database
GPG key ID: 4F3D7A0B17CC3D9C
4 changed files with 38 additions and 9 deletions

View file

@ -34,7 +34,10 @@ const keyCodeLookup = {
".": 190,
"/": 191,
"`": 192,
};
"!": 49,
"*": 56,
"@": 50,
} as const;
function isRequiredModifier(modifier: string): boolean {
return !modifier.endsWith("?");
@ -113,6 +116,7 @@ function keyCombinationToCheck(
keyCombination.slice(0, -1),
);
console.log({ keyCode, required, optional });
return check(keyCode, required, optional);
}

View file

@ -9,6 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { setFlag } from "@generated/backend";
import type { ReviewerState } from "../reviewer";
import type { MoreMenuItemInfo } from "./types";
import Shortcut from "$lib/components/Shortcut.svelte";
let showFloating = false;
let showFlags = false;
@ -114,8 +115,30 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
setFlag({ cardIds: [card!.id], flag: index });
$cardData!.queue!.cards[0].card!.flags = index;
}
function prepKeycodeForShortcut(keycode: string) {
return keycode.replace("Ctrl", "Control");
}
</script>
{#each shortcuts as shortcut}
{#if shortcut !== "hr"}
<Shortcut
keyCombination={prepKeycodeForShortcut(shortcut.shortcut)}
event="keydown"
on:action={shortcut.onClick}
/>
{/if}
{/each}
{#each flags as flag, i}
<Shortcut
keyCombination={prepKeycodeForShortcut(flag.shortcut)}
event="keydown"
on:action={() => changeFlag(i + 1)}
/>
{/each}
<MoreSubmenu bind:showFloating>
<button
slot="button"
@ -165,7 +188,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
? "RGBA(255,0,0,0.25)"
: ""}
>
<MoreItem shortcut={shortcut.shortcut} on:click={shortcut.onClick}>
<MoreItem
shortcut={shortcut.shortcut}
on:click={shortcut.onClick}
on:keydown={shortcut.onClick}
on:action={console.log}
>
{shortcut.name}
</MoreItem>
</div>

View file

@ -7,7 +7,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
</script>
<div class="row" on:click on:keydown role="button" tabindex="0">
<!--<Shortcut keyCombination={shortcut}></Shortcut>-->
<slot />
<span>{shortcut}</span>
</div>

View file

@ -259,12 +259,10 @@ export class ReviewerState {
break;
}
case "e": {
this.displayEditMenu();
break;
}
case "-": {
this.buryOrSuspendCurrentCard(false);
break;
if (!ctrl) {
this.displayEditMenu();
break;
}
}
}
}