|
331 | 331 | // Exported so DualPaneExplorer can forward keyboard events |
332 | 332 | export function handleKeyDown(e: KeyboardEvent) { |
333 | 333 | // Handle Enter key - navigate into selected item |
334 | | - if (e.key === 'Enter' && selectedEntry) { |
335 | | - e.preventDefault() |
336 | | - void handleNavigate(selectedEntry) |
337 | | - return |
| 334 | + // Use the list component's cached entry instead of selectedEntry to avoid race conditions |
| 335 | + // (selectedEntry is fetched asynchronously and may not be ready yet) |
| 336 | + if (e.key === 'Enter') { |
| 337 | + const listRef = viewMode === 'brief' ? briefListRef : fullListRef |
| 338 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment |
| 339 | + const entry: FileEntry | undefined = listRef?.getEntryAt(selectedIndex) |
| 340 | + if (entry) { |
| 341 | + e.preventDefault() |
| 342 | + void handleNavigate(entry) |
| 343 | + return |
| 344 | + } |
338 | 345 | } |
339 | 346 |
|
340 | 347 | // Handle Backspace or ⌘↑ - go to parent directory |
|
438 | 445 | $effect(() => { |
439 | 446 | void listen<string>('menu-action', (event) => { |
440 | 447 | const action = event.payload |
441 | | - if (action === 'open' && selectedEntry) { |
442 | | - void handleNavigate(selectedEntry) |
| 448 | + if (action === 'open') { |
| 449 | + // Use the list component's cached entry for consistency |
| 450 | + const listRef = viewMode === 'brief' ? briefListRef : fullListRef |
| 451 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment |
| 452 | + const entry: FileEntry | undefined = listRef?.getEntryAt(selectedIndex) |
| 453 | + if (entry) { |
| 454 | + void handleNavigate(entry) |
| 455 | + } |
443 | 456 | } |
444 | 457 | }) |
445 | 458 | .then((unsub) => { |
|
0 commit comments