@@ -6,11 +6,12 @@ import { DialogClose } from "@radix-ui/react-dialog";
66import { IconBraces , IconChartHistogram , IconFileTypeCsv } from "@tabler/icons-react" ;
77import { assertNever } from "assert-never" ;
88import { Maximize2 } from "lucide-react" ;
9- import { useCallback , useEffect , useRef , useState , type ReactNode } from "react" ;
9+ import { useCallback , useRef , useState , type ReactNode } from "react" ;
1010import { z } from "zod" ;
1111import { Card } from "~/components/primitives/charts/Card" ;
1212import { ShortcutKey } from "~/components/primitives/ShortcutKey" ;
1313import { SimpleTooltip } from "~/components/primitives/Tooltip" ;
14+ import { useShortcutKeys } from "~/hooks/useShortcutKeys" ;
1415import { cn } from "~/utils/cn" ;
1516import { rowsToCSV , rowsToJSON } from "~/utils/dataExport" ;
1617import { QueryResultsChart } from "../code/QueryResultsChart" ;
@@ -180,32 +181,15 @@ export function QueryWidget({
180181 const hasEditActions = onEdit || onRename || onDelete || onDuplicate ;
181182 const hasData = props . data . rows . length > 0 ;
182183
183- // "v" to fullscreen the hovered widget
184- useEffect ( ( ) => {
185- const handleKeyDown = ( e : KeyboardEvent ) => {
186- if ( isRenameDialogOpen || isMenuOpen ) return ;
187- if ( e . key !== "v" || e . metaKey || e . ctrlKey || e . altKey || e . shiftKey ) return ;
188-
189- // Ignore when typing in inputs/textareas/contenteditable
190- const target = e . target as HTMLElement ;
191- if (
192- target . tagName === "INPUT" ||
193- target . tagName === "TEXTAREA" ||
194- target . tagName === "SELECT" ||
195- target . isContentEditable
196- ) {
197- return ;
198- }
199-
200- // When not fullscreen, require hover to activate
201- if ( ! isFullscreen && ! containerRef . current ?. matches ( ":hover" ) ) return ;
202-
203- e . preventDefault ( ) ;
184+ // "v" to toggle fullscreen on hovered widget
185+ useShortcutKeys ( {
186+ shortcut : { key : "v" } ,
187+ action : useCallback ( ( ) => {
188+ const isHovered = containerRef . current ?. matches ( ":hover" ) ;
189+ if ( ! isFullscreen && ! isHovered ) return ;
204190 setIsFullscreen ( ( prev ) => ! prev ) ;
205- } ;
206- document . addEventListener ( "keydown" , handleKeyDown ) ;
207- return ( ) => document . removeEventListener ( "keydown" , handleKeyDown ) ;
208- } , [ isFullscreen , isRenameDialogOpen , isMenuOpen ] ) ;
191+ } , [ isFullscreen ] ) ,
192+ } ) ;
209193
210194 const copyToClipboard = useCallback ( ( text : string ) => {
211195 navigator . clipboard . writeText ( text ) ;
0 commit comments