From 5a8b9f403d02579fd965d7ba198d303dc9fbb31e Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 23 Apr 2021 11:22:30 +1000 Subject: [PATCH] move isApplePlatform() into lib/shortcuts, and remove sveltelib file --- ts/lib/shortcuts.ts | 21 +++++++++++++-------- ts/sveltelib/shortcuts.ts | 13 ------------- 2 files changed, 13 insertions(+), 21 deletions(-) delete mode 100644 ts/sveltelib/shortcuts.ts diff --git a/ts/lib/shortcuts.ts b/ts/lib/shortcuts.ts index 0a7312e12..5b3816496 100644 --- a/ts/lib/shortcuts.ts +++ b/ts/lib/shortcuts.ts @@ -6,21 +6,26 @@ export type Modifier = "Control" | "Alt" | "Shift" | "Meta"; const modifiers: Modifier[] = ["Control", "Alt", "Shift", "Meta"]; +function isApplePlatform(): boolean { + return ( + window.navigator.platform.startsWith("Mac") || + window.navigator.platform.startsWith("iP") + ); +} + // how modifiers are mapped -const platformModifiers = - navigator.platform === "MacIntel" - ? ["Meta", "Alt", "Shift", "Control"] - : ["Control", "Alt", "Shift", "OS"]; +const platformModifiers = isApplePlatform() + ? ["Meta", "Alt", "Shift", "Control"] + : ["Control", "Alt", "Shift", "OS"]; function splitKeyCombinationString(keyCombinationString: string): string[][] { return keyCombinationString.split(", ").map((segment) => segment.split("+")); } function modifiersToPlatformString(modifiers: string[]): string { - const displayModifiers = - navigator.platform === "MacIntel" - ? ["^", "⌥", "⇧", "⌘"] - : [`${tr.keyboardCtrl()}+`, "Alt+", `${tr.keyboardShift()}+`, "Win+"]; + const displayModifiers = isApplePlatform() + ? ["^", "⌥", "⇧", "⌘"] + : [`${tr.keyboardCtrl()}+`, "Alt+", `${tr.keyboardShift()}+`, "Win+"]; let result = ""; diff --git a/ts/sveltelib/shortcuts.ts b/ts/sveltelib/shortcuts.ts deleted file mode 100644 index 80a01ad0c..000000000 --- a/ts/sveltelib/shortcuts.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright: Ankitects Pty Ltd and contributors -// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html - -function isApplePlatform(): boolean { - return ( - window.navigator.platform.startsWith("Mac") || - window.navigator.platform.startsWith("iP") - ); -} - -export function primaryModifierForPlatform(): string { - return isApplePlatform() ? "Meta" : "Control"; -}