25 lines
615 B
JavaScript
25 lines
615 B
JavaScript
import React, { useRef, useEffect } from 'react';
|
|
|
|
const CtrlK = () => {
|
|
useEffect(() => {
|
|
const handleKeyPress = (event) => {
|
|
if (event.key === 'k' && (event.metaKey || event.ctrlKey)) {
|
|
event.preventDefault();
|
|
textFieldRef.current.focus();
|
|
}
|
|
|
|
if (event.key === 'Escape' && document.activeElement === textFieldRef.current) {
|
|
textFieldRef.current.blur();
|
|
}
|
|
};
|
|
|
|
document.addEventListener('keydown', handleKeyPress);
|
|
|
|
return () => {
|
|
document.removeEventListener('keydown', handleKeyPress);
|
|
};
|
|
}, [textFieldRef]);
|
|
};
|
|
|
|
export default CtrlK;
|