@@ -141,6 +141,7 @@ export default function AppLayout() {
141141 const todayNoteRef = useRef < DailyNote | null > ( null , ) ;
142142 const searchInputRef = useRef < HTMLInputElement > ( null , ) ;
143143 const searchResultRefs = useRef < ( HTMLButtonElement | null ) [ ] > ( [ ] , ) ;
144+ const searchNavigationModeRef = useRef < "mouse" | "keyboard" > ( "mouse" , ) ;
144145 useEffect ( ( ) => {
145146 todayNoteRef . current = todayNote ;
146147 } , [ todayNote , ] , ) ;
@@ -224,6 +225,7 @@ export default function AppLayout() {
224225
225226 if ( globalSearchOpen && globalSearchResults . length > 0 && event . key === "ArrowDown" ) {
226227 event . preventDefault ( ) ;
228+ searchNavigationModeRef . current = "keyboard" ;
227229 setGlobalSearchSelectedIndex ( ( prev , ) => {
228230 const lastIndex = globalSearchResults . length - 1 ;
229231 if ( prev < 0 ) return 0 ;
@@ -235,6 +237,7 @@ export default function AppLayout() {
235237
236238 if ( globalSearchOpen && globalSearchResults . length > 0 && event . key === "ArrowUp" ) {
237239 event . preventDefault ( ) ;
240+ searchNavigationModeRef . current = "keyboard" ;
238241 setGlobalSearchSelectedIndex ( ( prev , ) => {
239242 if ( prev <= 0 ) return 0 ;
240243 return prev - 1 ;
@@ -266,12 +269,22 @@ export default function AppLayout() {
266269
267270 useEffect ( ( ) => {
268271 if ( ! globalSearchOpen ) return ;
272+ searchNavigationModeRef . current = "mouse" ;
269273 const timer = window . setTimeout ( ( ) => {
270274 searchInputRef . current ?. focus ( ) ;
271275 } , 0 , ) ;
272276 return ( ) => window . clearTimeout ( timer , ) ;
273277 } , [ globalSearchOpen , ] , ) ;
274278
279+ useEffect ( ( ) => {
280+ if ( ! globalSearchOpen ) return ;
281+ const handleMouseMove = ( ) => {
282+ searchNavigationModeRef . current = "mouse" ;
283+ } ;
284+ window . addEventListener ( "mousemove" , handleMouseMove , { passive : true , } , ) ;
285+ return ( ) => window . removeEventListener ( "mousemove" , handleMouseMove , ) ;
286+ } , [ globalSearchOpen , ] , ) ;
287+
275288 useEffect ( ( ) => {
276289 if ( ! globalSearchOpen ) return ;
277290 const query = globalSearchQuery . trim ( ) ;
@@ -566,7 +579,10 @@ export default function AppLayout() {
566579 ? "border-gray-400 dark:border-gray-500 bg-gray-50 dark:bg-gray-800/80"
567580 : "border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 hover:border-gray-300 dark:hover:border-gray-600"
568581 } `}
569- onMouseEnter = { ( ) => setGlobalSearchSelectedIndex ( index , ) }
582+ onMouseEnter = { ( ) => {
583+ if ( searchNavigationModeRef . current !== "mouse" ) return ;
584+ setGlobalSearchSelectedIndex ( index , ) ;
585+ } }
570586 onClick = { ( ) => {
571587 openGlobalSearchResult ( result , ) ;
572588 } }
0 commit comments