From b162cb0b4142bd2fbcf0239fdaa1cb26ecce5242 Mon Sep 17 00:00:00 2001 From: 111-Vaishali Date: Wed, 22 Jul 2026 21:23:37 +0530 Subject: [PATCH] Add global keyboard shortcuts for analyze, clear, save, download, and theme toggle --- frontend/script.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/frontend/script.js b/frontend/script.js index 7c06caf9..3f86b8b3 100644 --- a/frontend/script.js +++ b/frontend/script.js @@ -99,6 +99,55 @@ codeInput.addEventListener('keydown', (e) => { runAnalysis(); } }); +// ── Global Keyboard Shortcuts ── +document.addEventListener('keydown', (e) => { + const isTyping = e.target === codeInput || e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA'; + + // Ctrl/Cmd + Enter → Analyze (works even outside textarea) + if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') { + e.preventDefault(); + if (!isAnalyzing) runAnalysis(); + return; + } + + // Ctrl/Cmd + K → focus code input + if ((e.ctrlKey || e.metaKey) && e.key === 'k') { + e.preventDefault(); + codeInput.focus(); + return; + } + + // Don't fire single-key shortcuts while user is typing + if (isTyping) return; + + // Ctrl/Cmd + Shift + C → Clear + if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key.toLowerCase() === 'c') { + e.preventDefault(); + document.getElementById('clearBtn').click(); + return; + } + + // Ctrl/Cmd + Shift + S → Save to favorites + if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key.toLowerCase() === 's') { + e.preventDefault(); + document.getElementById('saveBtn').click(); + return; + } + + // Ctrl/Cmd + D → Download result + if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'd') { + e.preventDefault(); + document.getElementById('downloadBtn').click(); + return; + } + + // Shift + D → toggle dark/light theme + if (e.shiftKey && e.key.toLowerCase() === 'd') { + e.preventDefault(); + themeToggle.click(); + return; + } +}); // ── File upload ── document.getElementById('uploadBtn').addEventListener('click', () => fileInput.click());