mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-03-05 22:17:42 +00:00
refator(code-editor): make CodeEditor feature based component
- replaced interfaces with types from main-content types
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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.ctrlKey || event.metaKey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.key === 's') {
|
||||
event.preventDefault();
|
||||
onSave();
|
||||
} else if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('keydown', handleKeyDown);
|
||||
return () => {
|
||||
document.removeEventListener('keydown', handleKeyDown);
|
||||
};
|
||||
}, [dependency, onClose, onSave]);
|
||||
};
|
||||
Reference in New Issue
Block a user