mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-07 05:45:39 +08:00
Refactor Settings, FileTree, GitPanel, Shell, and CodeEditor components (#402)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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]);
|
||||
};
|
||||
Reference in New Issue
Block a user