diff --git a/ts/editor/Tag.svelte b/ts/editor/Tag.svelte index 1ed890526..8a37a1cc9 100644 --- a/ts/editor/Tag.svelte +++ b/ts/editor/Tag.svelte @@ -7,6 +7,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import { nightModeKey } from "components/contextKeys"; import Badge from "components/Badge.svelte"; import { deleteIcon } from "./icons"; + import { controlPressed, shiftPressed } from "lib/keys"; export let name: string; @@ -23,39 +24,35 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html setTimeout(() => (flashing = false), 300); } - let showDelete = true; + let hideDelete = false; - function hideDeleteOnCtrlShfit(event: MouseEvent) { - showDelete = !event.ctrlKey && !event.shiftKey; + function setDeleteIcon(event: KeyboardEvent | MouseEvent) { + hideDelete = controlPressed(event) || shiftPressed(event); } - function showDeleteOnLeave() { - showDelete = true; - } - - function toggleDelete() { - // TODO + function showDeleteIcon() { + hideDelete = true; } const nightMode = getContext(nightModeKey); + + @@ -85,15 +82,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html &.flashing { animation: flash 0.3s linear; } + + &.hide-delete:hover :global(.delete-icon) { + opacity: 0; + } } - @include button.btn-day($with-active: false); - @include button.btn-night($with-active: false); - - $white-translucent: rgba(255 255 255 / 0.5); - $dark-translucent: rgba(0 0 0 / 0.2); - :global(.delete-icon > svg:hover) { + $white-translucent: rgba(255 255 255 / 0.5); + $dark-translucent: rgba(0 0 0 / 0.2); + .btn-day & { background-color: $dark-translucent; } @@ -102,4 +100,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html background-color: $white-translucent; } } + + @include button.btn-day($with-active: false); + @include button.btn-night($with-active: false); diff --git a/ts/lib/keys.ts b/ts/lib/keys.ts index 9e1683317..5d11893b1 100644 --- a/ts/lib/keys.ts +++ b/ts/lib/keys.ts @@ -4,15 +4,17 @@ import * as tr from "./i18n"; import { isApplePlatform } from "./platform"; +// those are the modifiers that Anki works with export type Modifier = "Control" | "Alt" | "Shift" | "Meta"; - -// how modifiers are mapped const allModifiers: Modifier[] = ["Control", "Alt", "Shift", "Meta"]; -const platformModifiers = isApplePlatform() +const platformModifiers: string[] = isApplePlatform() ? ["Meta", "Alt", "Shift", "Control"] : ["Control", "Alt", "Shift", "OS"]; +function translateModifierToPlatform(modifier: Modifier): string { + return platformModifiers[allModifiers.indexOf(modifier)]; +} export const checkModifiers = (required: Modifier[], optional: Modifier[] = []) => @@ -31,15 +33,18 @@ export const checkModifiers = ); }; -export const hasModifier = (modifier: Modifier) => (event: KeyboardEvent): boolean => event.getModifierState(platformModifiers[allModifiers.indexOf(modifier)]); +const modifierPressed = + (modifier: Modifier) => + (event: MouseEvent | KeyboardEvent): boolean => { + const translated = translateModifierToPlatform(modifier); + const state = event.getModifierState(translated); + return event.type === "keyup" + ? state && (event as KeyboardEvent).key !== translated + : state; + }; -export function isControl(key: string): boolean { - return key === platformModifiers[0]; -} - -export function isShift(key: string): boolean { - return key === platformModifiers[2]; -} +export const controlPressed = modifierPressed("Control"); +export const shiftPressed = modifierPressed("Shift"); export function modifiersToPlatformString(modifiers: string[]): string { const displayModifiers = isApplePlatform()