mirror of
				https://github.com/ItzCrazyKns/Perplexica.git
				synced 2025-11-04 04:38:15 +00:00 
			
		
		
		
	feat(textarea): handle "/" keys
This commit is contained in:
		@@ -18,14 +18,21 @@ const EmptyChatMessageInput = ({
 | 
			
		||||
 | 
			
		||||
  const inputRef = useRef<HTMLTextAreaElement | null>(null);
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    const handleKeyDown = (e: KeyboardEvent) => {
 | 
			
		||||
    if (e.key === '/') {
 | 
			
		||||
      const activeElement = document.activeElement;
 | 
			
		||||
 | 
			
		||||
      const isInputFocused =
 | 
			
		||||
        activeElement?.tagName === 'INPUT' ||
 | 
			
		||||
        activeElement?.tagName === 'TEXTAREA' ||
 | 
			
		||||
        activeElement?.hasAttribute('contenteditable');
 | 
			
		||||
 | 
			
		||||
      if (e.key === '/' && !isInputFocused) {
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        inputRef.current?.focus();
 | 
			
		||||
      }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    document.addEventListener('keydown', handleKeyDown);
 | 
			
		||||
 | 
			
		||||
    return () => {
 | 
			
		||||
 
 | 
			
		||||
@@ -27,14 +27,21 @@ const MessageInput = ({
 | 
			
		||||
 | 
			
		||||
  const inputRef = useRef<HTMLTextAreaElement | null>(null);
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    const handleKeyDown = (e: KeyboardEvent) => {
 | 
			
		||||
    if (e.key === '/') {
 | 
			
		||||
      const activeElement = document.activeElement;
 | 
			
		||||
 | 
			
		||||
      const isInputFocused =
 | 
			
		||||
        activeElement?.tagName === 'INPUT' ||
 | 
			
		||||
        activeElement?.tagName === 'TEXTAREA' ||
 | 
			
		||||
        activeElement?.hasAttribute('contenteditable');
 | 
			
		||||
 | 
			
		||||
      if (e.key === '/' && !isInputFocused) {
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        inputRef.current?.focus();
 | 
			
		||||
      }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    document.addEventListener('keydown', handleKeyDown);
 | 
			
		||||
 | 
			
		||||
    return () => {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user