mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-03-05 14:07:40 +00:00
38 lines
825 B
TypeScript
38 lines
825 B
TypeScript
import { useEffect } from 'react';
|
|
|
|
type UseEditorKeyboardShortcutsParams = {
|
|
onSave: () => void;
|
|
onClose: () => void;
|
|
dependency: string;
|
|
};
|
|
|
|
export const useEditorKeyboardShortcuts = ({
|
|
onSave,
|
|
onClose,
|
|
dependency,
|
|
}: UseEditorKeyboardShortcutsParams) => {
|
|
useEffect(() => {
|
|
const handleKeyDown = (event: KeyboardEvent) => {
|
|
if (event.key === 'Escape') {
|
|
event.preventDefault();
|
|
onClose();
|
|
return;
|
|
}
|
|
|
|
if (!(event.ctrlKey || event.metaKey)) {
|
|
return;
|
|
}
|
|
|
|
if (event.key.toLowerCase() === 's') {
|
|
event.preventDefault();
|
|
onSave();
|
|
}
|
|
};
|
|
|
|
document.addEventListener('keydown', handleKeyDown);
|
|
return () => {
|
|
document.removeEventListener('keydown', handleKeyDown);
|
|
};
|
|
}, [dependency, onClose, onSave]);
|
|
};
|