Skip to content

Commit bf7aab1

Browse files
committed
refactor: migrate mod + k to useHotkeys to reduce usage
1 parent c7f1a11 commit bf7aab1

4 files changed

Lines changed: 33 additions & 18 deletions

File tree

pnpm-lock.yaml

Lines changed: 21 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/components/CodeEditor/html.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ interface HtmlEditorProps {
1919
}
2020

2121
export const HtmlEditor = React.forwardRef<HtmlEditorRef, HtmlEditorProps>(
22-
({ value, onChange, height = 400, readOnly = false, onValidate, onSave }, ref) => {
22+
(
23+
{ value, onChange, height = 400, readOnly = false, onValidate, onSave },
24+
ref
25+
) => {
2326
const editorRef = useRef<any>(null);
2427
const monacoRef = useRef<any>(null);
2528
const colorScheme = useTheme();

src/client/components/CommandPanel/index.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useMemo, useState } from 'react';
1+
import React, { useMemo, useState } from 'react';
22
import {
33
Command,
44
CommandDialog,
@@ -25,6 +25,7 @@ import {
2525
import { RiSurveyLine } from 'react-icons/ri';
2626

2727
import { NavigateOptions, useNavigate } from '@tanstack/react-router';
28+
import { useHotkeys } from 'react-hotkeys-hook';
2829
import { useEvent } from '@/hooks/useEvent';
2930
import { useCommandState } from 'cmdk';
3031
import { useTranslation } from '@i18next-toolkit/react';
@@ -62,19 +63,11 @@ export const CommandPanel: React.FC<CommandPanelProps> = React.memo((props) => {
6263
};
6364
});
6465

65-
useEffect(() => {
66-
const down = (e: KeyboardEvent) => {
67-
if (e.key === 'k' && (e.metaKey || e.ctrlKey)) {
68-
e.preventDefault();
69-
setOpen((open) => !open);
70-
}
71-
};
72-
73-
document.addEventListener('keydown', down);
74-
return () => {
75-
document.removeEventListener('keydown', down);
76-
};
77-
}, []);
66+
// Handle keyboard shortcut Cmd+K / Ctrl+K to toggle command panel
67+
useHotkeys('mod+k', (event) => {
68+
event.preventDefault();
69+
setOpen((open) => !open);
70+
});
7871

7972
return (
8073
<>

src/client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"react-grid-layout": "1.4.2",
100100
"react-helmet": "^6.1.0",
101101
"react-hook-form": "^7.54.2",
102+
"react-hotkeys-hook": "^5.2.4",
102103
"react-icons": "^5.5.0",
103104
"react-identicons": "^1.2.5",
104105
"react-leaflet": "^4.2.1",

0 commit comments

Comments
 (0)