Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import HowItWorks from "./components/HowItWorks"
import ExampleRepos from "./components/ExampleRepos"
import { usePrefersReducedMotion } from "./hooks/usePrefersReducedMotion"
import { useToast } from "./components/Toast"
import { useKeyboardShortcuts } from "./hooks/useKeyboardShortcuts"
import { useHistory } from "./hooks/useHistory"
import HistoryPanel from "./components/HistoryPanel"

Expand Down Expand Up @@ -93,6 +94,13 @@ export default function App() {
}
}

// Keyboard shortcuts
useKeyboardShortcuts({
"1": () => setActiveTab("violations"),
"2": () => setActiveTab("remediation"),
"escape": () => setError(""),
})

// Focus management: move focus to results after analysis completes
useEffect(() => {
if (result && !loading && resultsRef.current) {
Expand Down
31 changes: 31 additions & 0 deletions frontend/src/hooks/useKeyboardShortcuts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useEffect } from "react"

interface Shortcuts {
[key: string]: () => void
}

export function useKeyboardShortcuts(shortcuts: Shortcuts) {
useEffect(() => {
const handler = (e: KeyboardEvent) => {
const target = e.target as HTMLElement
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) {
return
}

const parts: string[] = []
if (e.ctrlKey || e.metaKey) parts.push("ctrl")
if (e.shiftKey) parts.push("shift")
if (e.altKey) parts.push("alt")
parts.push(e.key.toLowerCase())
const combo = parts.join("+")

if (combo in shortcuts) {
e.preventDefault()
shortcuts[combo]()
}
}

window.addEventListener("keydown", handler)
return () => window.removeEventListener("keydown", handler)
}, [shortcuts])
}
Loading