move isApplePlatform() into lib/shortcuts, and remove sveltelib file

This commit is contained in:
Damien Elmes 2021-04-23 11:22:30 +10:00
parent 79b62682ab
commit 5a8b9f403d
2 changed files with 13 additions and 21 deletions

View File

@ -6,21 +6,26 @@ export type Modifier = "Control" | "Alt" | "Shift" | "Meta";
const modifiers: 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 // how modifiers are mapped
const platformModifiers = const platformModifiers = isApplePlatform()
navigator.platform === "MacIntel" ? ["Meta", "Alt", "Shift", "Control"]
? ["Meta", "Alt", "Shift", "Control"] : ["Control", "Alt", "Shift", "OS"];
: ["Control", "Alt", "Shift", "OS"];
function splitKeyCombinationString(keyCombinationString: string): string[][] { function splitKeyCombinationString(keyCombinationString: string): string[][] {
return keyCombinationString.split(", ").map((segment) => segment.split("+")); return keyCombinationString.split(", ").map((segment) => segment.split("+"));
} }
function modifiersToPlatformString(modifiers: string[]): string { function modifiersToPlatformString(modifiers: string[]): string {
const displayModifiers = const displayModifiers = isApplePlatform()
navigator.platform === "MacIntel" ? ["^", "⌥", "⇧", "⌘"]
? ["^", "⌥", "⇧", "⌘"] : [`${tr.keyboardCtrl()}+`, "Alt+", `${tr.keyboardShift()}+`, "Win+"];
: [`${tr.keyboardCtrl()}+`, "Alt+", `${tr.keyboardShift()}+`, "Win+"];
let result = ""; let result = "";

View File

@ -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";
}