diff --git a/ui/components/EmptyChatMessageInput.tsx b/ui/components/EmptyChatMessageInput.tsx index 0ff9b2e..39d3f16 100644 --- a/ui/components/EmptyChatMessageInput.tsx +++ b/ui/components/EmptyChatMessageInput.tsx @@ -18,14 +18,21 @@ const EmptyChatMessageInput = ({ const inputRef = useRef(null); - const handleKeyDown = (e: KeyboardEvent) => { - if (e.key === '/') { - e.preventDefault(); - inputRef.current?.focus(); - } - }; - useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + const activeElement = document.activeElement; + + const isInputFocused = + activeElement?.tagName === 'INPUT' || + activeElement?.tagName === 'TEXTAREA' || + activeElement?.hasAttribute('contenteditable'); + + if (e.key === '/' && !isInputFocused) { + e.preventDefault(); + inputRef.current?.focus(); + } + }; + document.addEventListener('keydown', handleKeyDown); return () => { diff --git a/ui/components/MessageInput.tsx b/ui/components/MessageInput.tsx index 2229cdf..05d44a6 100644 --- a/ui/components/MessageInput.tsx +++ b/ui/components/MessageInput.tsx @@ -27,14 +27,21 @@ const MessageInput = ({ const inputRef = useRef(null); - const handleKeyDown = (e: KeyboardEvent) => { - if (e.key === '/') { - e.preventDefault(); - inputRef.current?.focus(); - } - }; - useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + const activeElement = document.activeElement; + + const isInputFocused = + activeElement?.tagName === 'INPUT' || + activeElement?.tagName === 'TEXTAREA' || + activeElement?.hasAttribute('contenteditable'); + + if (e.key === '/' && !isInputFocused) { + e.preventDefault(); + inputRef.current?.focus(); + } + }; + document.addEventListener('keydown', handleKeyDown); return () => {