Timothy J. Baek 10 months ago
parent
commit
aa7d25600f
1 changed files with 9 additions and 6 deletions
  1. 9 6
      src/lib/components/common/CodeEditor.svelte

+ 9 - 6
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);
 		};
 	});
 </script>