@@ -16,6 +16,8 @@ import { hide_coco } from "@/commands";
1616import { DataSource } from "@/types/commands" ;
1717import InputExtra from "./InputExtra" ;
1818import { useConnectStore } from "@/stores/connectStore" ;
19+ import { useShortcutsStore } from "@/stores/shortcutsStore" ;
20+ import { useKeyPress } from "ahooks" ;
1921
2022interface ChatInputProps {
2123 onSend : ( message : string ) => void ;
@@ -73,7 +75,7 @@ export default function ChatInput({
7375 getFileIcon,
7476} : ChatInputProps ) {
7577 const { t } = useTranslation ( ) ;
76-
78+
7779 const showTooltip = useAppStore (
7880 ( state : { showTooltip : boolean } ) => state . showTooltip
7981 ) ;
@@ -88,6 +90,14 @@ export default function ChatInput({
8890 ) ;
8991
9092 const sessionId = useConnectStore ( ( state ) => state . currentSessionId ) ;
93+ const modifierKey = useShortcutsStore ( ( state ) => {
94+ return state . modifierKey ;
95+ } ) ;
96+ const modifierKeyPressed = useShortcutsStore ( ( state ) => {
97+ return state . modifierKeyPressed ;
98+ } ) ;
99+ const modeSwitch = useShortcutsStore ( ( state ) => state . modeSwitch ) ;
100+ const returnToInput = useShortcutsStore ( ( state ) => state . returnToInput ) ;
91101
92102 useEffect ( ( ) => {
93103 return ( ) => {
@@ -109,7 +119,7 @@ export default function ChatInput({
109119 setReconnectCountdown ( 0 ) ;
110120 return ;
111121 }
112-
122+
113123 if ( reconnectCountdown > 0 ) {
114124 const timer = setTimeout ( ( ) => {
115125 setReconnectCountdown ( reconnectCountdown - 1 ) ;
@@ -119,6 +129,22 @@ export default function ChatInput({
119129 } , [ reconnectCountdown , connected ] ) ;
120130
121131 const [ isCommandPressed , setIsCommandPressed ] = useState ( false ) ;
132+ const setModifierKeyPressed = useShortcutsStore ( ( state ) => {
133+ return state . setModifierKeyPressed ;
134+ } ) ;
135+
136+ useEffect ( ( ) => {
137+ const handleFocus = ( ) => {
138+ setIsCommandPressed ( false ) ;
139+ setModifierKeyPressed ( false ) ;
140+ } ;
141+
142+ window . addEventListener ( "focus" , handleFocus ) ;
143+
144+ return ( ) => {
145+ window . removeEventListener ( "focus" , handleFocus ) ;
146+ } ;
147+ } , [ ] ) ;
122148
123149 const handleToggleFocus = useCallback ( ( ) => {
124150 if ( isChatMode ) {
@@ -146,6 +172,8 @@ export default function ChatInput({
146172 }
147173 } , [ inputValue , isPinned ] ) ;
148174
175+ useKeyPress ( `${ modifierKey } .${ returnToInput } ` , handleToggleFocus ) ;
176+
149177 const handleKeyDown = useCallback (
150178 ( e : KeyboardEvent ) => {
151179 // console.log("handleKeyDown", e.code, e.key);
@@ -167,8 +195,6 @@ export default function ChatInput({
167195 case "Comma" :
168196 setIsCommandPressed ( false ) ;
169197 break ;
170- case "KeyI" :
171- handleToggleFocus ( ) ;
172198 break ;
173199 case "ArrowLeft" :
174200 setSourceData ( undefined ) ;
@@ -299,13 +325,13 @@ export default function ChatInput({
299325 ←
300326 </ div >
301327 ) : null }
302- { showTooltip && isCommandPressed ? (
328+ { showTooltip && modifierKeyPressed ? (
303329 < div
304330 className = { `absolute ${
305331 ! isChatMode && sourceData ? "left-7" : ""
306332 } w-4 h-4 flex items-center justify-center font-normal text-xs text-[#333] leading-[14px] bg-[#ccc] dark:bg-[#6B6B6B] rounded-md shadow-[-6px_0px_6px_2px_#ededed] dark:shadow-[-6px_0px_6px_2px_#202126]`}
307333 >
308- I
334+ { returnToInput }
309335 </ div >
310336 ) : null }
311337 </ div >
@@ -344,13 +370,13 @@ export default function ChatInput({
344370 </ button >
345371 ) : null }
346372
347- { showTooltip && isChatMode && isCommandPressed ? (
373+ { /* { showTooltip && isChatMode && isCommandPressed ? (
348374 <div
349375 className={`absolute right-10 w-4 h-4 flex items-center justify-center font-normal text-xs text-[#333] leading-[14px] bg-[#ccc] dark:bg-[#6B6B6B] rounded-md shadow-[-6px_0px_6px_2px_#fff] dark:shadow-[-6px_0px_6px_2px_#000]`}
350376 >
351377 M
352378 </div>
353- ) : null }
379+ ) : null} */ }
354380
355381 { showTooltip && isChatMode && isCommandPressed ? (
356382 < div
@@ -371,7 +397,7 @@ export default function ChatInput({
371397 } }
372398 >
373399 { reconnectCountdown > 0
374- ? `${ t ( "search.input.connecting" ) } (${ reconnectCountdown } s)`
400+ ? `${ t ( "search.input.connecting" ) } (${ reconnectCountdown } s)`
375401 : t ( "search.input.reconnect" ) }
376402 </ div >
377403 </ div >
@@ -440,11 +466,11 @@ export default function ChatInput({
440466
441467 { isChatPage ? null : (
442468 < div className = "relative w-16 flex justify-end items-center" >
443- { showTooltip && isCommandPressed ? (
469+ { showTooltip && modifierKeyPressed ? (
444470 < div
445471 className = { `absolute left-1 z-10 w-4 h-4 flex items-center justify-center font-normal text-xs text-[#333] leading-[14px] bg-[#ccc] dark:bg-[#6B6B6B] rounded-md shadow-[-6px_0px_6px_2px_#fff] dark:shadow-[-6px_0px_6px_2px_#000]` }
446472 >
447- T
473+ { modeSwitch }
448474 </ div >
449475 ) : null }
450476 < ChatSwitch
0 commit comments