From aa7d25600f2b31d94c8d44b8dcb5fbf3bf2de075 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 10 Jun 2024 22:33:25 -0700 Subject: [PATCH] refac --- src/lib/components/common/CodeEditor.svelte | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/components/common/CodeEditor.svelte b/src/lib/components/common/CodeEditor.svelte index ef923b09f..0822ac019 100644 --- a/src/lib/components/common/CodeEditor.svelte +++ b/src/lib/components/common/CodeEditor.svelte @@ -110,21 +110,24 @@ attributeFilter: ['class'] }); - // Add a keyboard shortcut to format the code when Ctrl/Cmd + S is pressed - // Override the default browser save functionality - - const handleSave = async (e) => { + const keydownHandler = async (e) => { if ((e.ctrlKey || e.metaKey) && e.key === 's') { e.preventDefault(); dispatch('save'); } + + // Format code when Ctrl + Shift + F is pressed + if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === 'f') { + e.preventDefault(); + await formatPythonCodeHandler(); + } }; - document.addEventListener('keydown', handleSave); + document.addEventListener('keydown', keydownHandler); return () => { observer.disconnect(); - document.removeEventListener('keydown', handleSave); + document.removeEventListener('keydown', keydownHandler); }; });