Skip to content

Commit

Permalink
feat(components): keyboard based scaling in preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Cubxity committed May 8, 2023
1 parent 34b33ec commit c001cf3
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/components/Preview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,25 @@
}
};
onMount(() => {
// Returns an unlisten function
return appWindow.listen<TypstCompileEvent>("typst_compile", ({ event, payload }) => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.ctrlKey) {
switch (event.key) {
// Zoom in
case "=":
case "+":
event.preventDefault();
scale = scales[scaleIndex = Math.min(scaleIndex + 1, scales.length - 1)];
break;
case "-":
event.preventDefault();
scale = scales[scaleIndex = Math.max(scaleIndex - 1, 0)];
break;
}
}
};
onMount(async () => {
const unsubscribe = await appWindow.listen<TypstCompileEvent>("typst_compile", ({ _, payload }) => {
const { document } = payload;
if (document) {
pages = document.pages;
Expand All @@ -65,6 +81,13 @@
height = document.height;
}
});
window.addEventListener("keydown", handleKeyDown);
return () => {
unsubscribe();
window.removeEventListener("keydown", handleKeyDown);
};
});
</script>

Expand Down

0 comments on commit c001cf3

Please sign in to comment.