catch ctrl/cmd+enter to save settings
This commit is contained in:
parent
dc46ece8f2
commit
1ddfd73da6
@ -26,6 +26,7 @@ compile_svelte(
|
|||||||
name = "svelte",
|
name = "svelte",
|
||||||
srcs = svelte_files,
|
srcs = svelte_files,
|
||||||
deps = [
|
deps = [
|
||||||
|
"//ts/sveltelib",
|
||||||
"@npm//@types/bootstrap",
|
"@npm//@types/bootstrap",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -94,6 +95,7 @@ esbuild(
|
|||||||
":bootstrap-icons",
|
":bootstrap-icons",
|
||||||
"@npm//bootstrap",
|
"@npm//bootstrap",
|
||||||
":base_css",
|
":base_css",
|
||||||
|
"//ts/sveltelib",
|
||||||
] + svelte_names,
|
] + svelte_names,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -6,8 +6,21 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
import ConfigSelector from "./ConfigSelector.svelte";
|
import ConfigSelector from "./ConfigSelector.svelte";
|
||||||
import ConfigEditor from "./ConfigEditor.svelte";
|
import ConfigEditor from "./ConfigEditor.svelte";
|
||||||
import type { DeckConfigState } from "./lib";
|
import type { DeckConfigState } from "./lib";
|
||||||
|
import { primaryModifierForPlatform } from "sveltelib/shortcuts";
|
||||||
|
|
||||||
export let state: DeckConfigState;
|
export let state: DeckConfigState;
|
||||||
|
|
||||||
|
function onKeyDown(evt: KeyboardEvent): void {
|
||||||
|
if (
|
||||||
|
evt.code === "Enter" &&
|
||||||
|
evt.getModifierState(primaryModifierForPlatform())
|
||||||
|
) {
|
||||||
|
state.save(false);
|
||||||
|
} else {
|
||||||
|
console.log(evt.getModifierState(primaryModifierForPlatform()));
|
||||||
|
console.log(primaryModifierForPlatform());
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@ -17,6 +30,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<div on:keydown={onKeyDown}>
|
||||||
<div id="modal">
|
<div id="modal">
|
||||||
<!-- filled in later-->
|
<!-- filled in later-->
|
||||||
</div>
|
</div>
|
||||||
@ -26,3 +40,4 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
<div class="editor">
|
<div class="editor">
|
||||||
<ConfigEditor {state} />
|
<ConfigEditor {state} />
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
@ -33,6 +33,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
function onKeyUp(evt: KeyboardEvent): void {
|
function onKeyUp(evt: KeyboardEvent): void {
|
||||||
if (evt.code === "Enter") {
|
if (evt.code === "Enter") {
|
||||||
|
evt.stopPropagation();
|
||||||
onOkClicked();
|
onOkClicked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
ts/sveltelib/shortcuts.ts
Normal file
13
ts/sveltelib/shortcuts.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// 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";
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user