det ser ut som en inställningsmeny för kortkommandon

This commit is contained in:
botvid johansson 2025-04-24 14:52:06 +02:00
parent 6c71123fd7
commit 3b57f22e6e
5 changed files with 132 additions and 111 deletions

View File

@ -1,8 +1,10 @@
<script> <script>
import { hotkeys } from '$lib/hotkey-actions';
import Button from '$lib/components/ui/button/button.svelte'; import Button from '$lib/components/ui/button/button.svelte';
import * as Card from '$lib/components/ui/card/index'; import * as Card from '$lib/components/ui/card/index';
import { appState } from '$lib/stores.svelte'; import { appState } from '$lib/stores.svelte';
import { clickOutside } from 'svelte-outside'; import { clickOutside } from 'svelte-outside';
import Input from '$lib/components/ui/input/input.svelte';
var show = true; var show = true;
const cancelSave = () => true; const cancelSave = () => true;
const handleSave = () => true; const handleSave = () => true;
@ -15,12 +17,23 @@
{#if show} {#if show}
<div use:clickOutside={close}> <div use:clickOutside={close}>
<Card.Root class="mx-auto w-[490px]"> <Card.Root class="mx-auto w-[590px]">
<Card.Header> <Card.Header>
<Card.Title>Konfigurera kortkommandon</Card.Title> <Card.Title>Konfigurera kortkommandon</Card.Title>
<Card.Description></Card.Description> <Card.Description></Card.Description>
</Card.Header> </Card.Header>
<Card.Content class="mx-auto"></Card.Content> <Card.Content class="mx-auto"></Card.Content>
<div class="grid grid-cols-5 gap-2">
{#each hotkeys as hotkey}
<div class="col-span-4">
<Input class="w-[290px]" readonly bind:value={hotkey[1].name} />
</div>
<div>
<Input class="w-[100px]" bind:value={hotkey[0]} />
</div>
{/each}
</div>
<br />
<Card.Footer class="flex justify-between"> <Card.Footer class="flex justify-between">
<Button on:click={cancelSave} variant="outline">Avbryt</Button> <Button on:click={cancelSave} variant="outline">Avbryt</Button>
<Button on:click={handleSave}>Spara</Button> <Button on:click={handleSave}>Spara</Button>

112
src/lib/hotkey-actions.js Normal file
View File

@ -0,0 +1,112 @@
import { goto } from '$app/navigation';
import { PUBLIC_TAURI } from '$env/static/public';
import { getCurrentWindow } from "@tauri-apps/api/window";
import { incTextSize, decTextSize, selectNextColor, toggleMenuOpen, appState } from "$lib/stores.svelte"
let fullscreen = true;
export const hotkeys = new Map();
hotkeys.set("Home", {
name: "Debug-ruta på/av",
action: (e) => {
e.preventDefault()
appState.debug = !appState.debug;
}
})
hotkeys.set("F4", {
name: "Rensa textfält",
action: (e) => {
e.preventDefault()
console.log("Clear text", appState.text)
appState.text = ""
}
})
hotkeys.set("F5", {
name: "Öppna meny",
action: (e) => {
e.preventDefault()
toggleMenuOpen()
console.log("Menu open", appState.menuOpen)
}
})
hotkeys.set("F6", {
name: "Minska textstorlek",
action: (e) => {
e.preventDefault()
console.log("Decrease text size")
decTextSize()
}
})
hotkeys.set("F7", {
name: "Öka textstorlek",
action: (e) => {
e.preventDefault()
console.log("Increase text size")
incTextSize()
}
})
hotkeys.set("F8", {
name: "Växla mellan färginställningar",
action: (e) => {
e.preventDefault()
console.log("Cycle through text and background colors")
selectNextColor()
}
})
hotkeys.set("F2", {
name: "Lägg till förkortning",
action: (e) => {
e.preventDefault()
toggleMenuOpen(false)
appState.open = "create"
}
})
hotkeys.set("F11", {
name: "Växla fullskärmsläge",
action: (e) => {
console.log("Toggle fullscreen")
console.log(PUBLIC_TAURI)
if (PUBLIC_TAURI == true) {
e.preventDefault()
if (fullscreen) {
getCurrentWindow().setFullscreen(false).then(() => {
fullscreen = false
});
} else {
getCurrentWindow().setFullscreen(true).then(() => {
fullscreen = true
});
}
}
}
})
hotkeys.set("F12", {
name: "Öppna import-rutan",
action: (e) => {
e.preventDefault()
console.log("Open import page")
goto("/import")
}
})
hotkeys.set("Escape", {
name: "Stäng aktiva dialogrutor och fokusera på texten",
action: (e) => {
e.preventDefault()
console.log("Close stuff")
appState.open = ""
}
})

View File

@ -51,6 +51,6 @@ export function resumeHotkeys() {
hotkeys.unpause(); hotkeys.unpause();
} }
export function setHotkeeyScope(scope) { export function setHotkeyScope(scope) {
hotkeys.setScope(scope); hotkeys.setScope(scope);
} }

View File

@ -1,12 +1,5 @@
import { goto } from '$app/navigation';
import { PUBLIC_TAURI } from '$env/static/public';
import type { ExpanderType } from "./index.d.ts"; import type { ExpanderType } from "./index.d.ts";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { incTextSize, decTextSize, selectNextColor, toggleMenuOpen, appState } from "$lib/stores.svelte"
let fullscreen = true;
export const defaultExpanders: Map<string, ExpanderType> = new Map(); export const defaultExpanders: Map<string, ExpanderType> = new Map();
export const hotkeys: Map<string, any> = new Map();
defaultExpanders.set("\n", { defaultExpanders.set("\n", {
key: { keyCode: 188, shiftKey: false }, key: { keyCode: 188, shiftKey: false },
@ -84,95 +77,3 @@ defaultExpanders.set(";", {
fullstop: false, fullstop: false,
}); });
hotkeys.set("Home", {
action: (e) => {
e.preventDefault()
appState.debug = !appState.debug;
}
})
hotkeys.set("F4", {
action: (e) => {
e.preventDefault()
console.log("Clear text", appState.text)
appState.text = ""
}
})
hotkeys.set("F5", {
action: (e) => {
e.preventDefault()
toggleMenuOpen()
console.log("Menu open", appState.menuOpen)
}
})
hotkeys.set("F6", {
action: (e) => {
e.preventDefault()
console.log("Decrease text size")
decTextSize()
}
})
hotkeys.set("F7", {
action: (e) => {
e.preventDefault()
console.log("Increase text size")
incTextSize()
}
})
hotkeys.set("F8", {
action: (e) => {
e.preventDefault()
console.log("Increase text size")
selectNextColor()
}
})
hotkeys.set("F2", {
action: (e) => {
e.preventDefault()
toggleMenuOpen(false)
appState.open = "create"
}
})
hotkeys.set("F11", {
action: (e) => {
console.log("Toggle fullscreen")
console.log(PUBLIC_TAURI)
if (PUBLIC_TAURI == true) {
e.preventDefault()
if (fullscreen) {
getCurrentWindow().setFullscreen(false).then(() => {
fullscreen = false
});
} else {
getCurrentWindow().setFullscreen(true).then(() => {
fullscreen = true
});
}
}
}
})
hotkeys.set("F12", {
action: (e) => {
e.preventDefault()
console.log("Open import page")
goto("/import")
}
})
hotkeys.set("Escape", {
action: (e) => {
e.preventDefault()
console.log("Close stuff")
appState.open = ""
}
})

View File

@ -12,19 +12,18 @@
import { initHotkeys, registerAllHotkeys, registerHotkeys } from '$lib/hotkeys'; import { initHotkeys, registerAllHotkeys, registerHotkeys } from '$lib/hotkeys';
let loaded = false; let loaded = false;
$effect(() => { $effect(() => {
console.log(appState.open);
appState.open; appState.open;
if (loaded) { if (loaded) {
if (appState.open == '' && textarea != undefined) { if (appState.open == '' && textarea != undefined) {
textarea.focus(); textarea.focus();
} }
if (appState.open == 'selectLists') { if (appState.open == 'selectLists') {
console.log('should close dashboard'); // console.log('should close dashboard');
showDashboard = false; showDashboard = false;
return; return;
} }
if (appState.open == 'dashboard') { if (appState.open == 'dashboard') {
console.log('should open dashboard'); // console.log('should open dashboard');
showDashboard = true; showDashboard = true;
} }
} }
@ -32,17 +31,13 @@
debugState = JSON.stringify(appState, null, 4); debugState = JSON.stringify(appState, null, 4);
debugShortforms = JSON.stringify(shortforms, null, 4); debugShortforms = JSON.stringify(shortforms, null, 4);
}); });
import { hotkeys } from '../modules/keyboard'; var showDashboard = $state(false);
var showDashboard = $state(true);
import { Toaster } from '$lib/components/ui/sonner'; import { Toaster } from '$lib/components/ui/sonner';
import { onDestroy, onMount } from 'svelte'; import { onDestroy, onMount } from 'svelte';
import { preventDefault } from 'svelte/legacy'; import { preventDefault } from 'svelte/legacy';
const handleHotkeys = (e: KeyboardEvent) => {
hotkeys.get(e.key)?.action(e);
};
let textarea: HTMLTextAreaElement | undefined = $state(); let textarea: HTMLTextAreaElement | undefined = $state();
onMount(() => { onMount(() => {
appState.open = 'dashboard'; appState.open = 'hotkeys';
initHotkeys({ scope: 'main', filterInputs: false }); initHotkeys({ scope: 'main', filterInputs: false });
registerHotkeys( registerHotkeys(
@ -70,7 +65,7 @@
<svelte:head> <svelte:head>
<title>SKRIVERT</title> <title>SKRIVERT</title>
</svelte:head> </svelte:head>
<svelte:window on:keydown={handleHotkeys} /> <svelte:window />
<div class="h-dvh w-full overflow-hidden" role="application"> <div class="h-dvh w-full overflow-hidden" role="application">
{#if appState.debug} {#if appState.debug}