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, ".": 190,
"/": 191, "/": 191,
"`": 192, "`": 192,
}; "!": 49,
"*": 56,
"@": 50,
} as const;
function isRequiredModifier(modifier: string): boolean { function isRequiredModifier(modifier: string): boolean {
return !modifier.endsWith("?"); return !modifier.endsWith("?");
@ -113,6 +116,7 @@ function keyCombinationToCheck(
keyCombination.slice(0, -1), keyCombination.slice(0, -1),
); );
console.log({ keyCode, required, optional });
return check(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 { setFlag } from "@generated/backend";
import type { ReviewerState } from "../reviewer"; import type { ReviewerState } from "../reviewer";
import type { MoreMenuItemInfo } from "./types"; import type { MoreMenuItemInfo } from "./types";
import Shortcut from "$lib/components/Shortcut.svelte";
let showFloating = false; let showFloating = false;
let showFlags = 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 }); setFlag({ cardIds: [card!.id], flag: index });
$cardData!.queue!.cards[0].card!.flags = index; $cardData!.queue!.cards[0].card!.flags = index;
} }
function prepKeycodeForShortcut(keycode: string) {
return keycode.replace("Ctrl", "Control");
}
</script> </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> <MoreSubmenu bind:showFloating>
<button <button
slot="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)" ? "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} {shortcut.name}
</MoreItem> </MoreItem>
</div> </div>

View file

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

View file

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