(model, viewMode = null, thumbPriority = THUMB_PRIORITY_BACKGROUND)
| 17547 | |
| 17548 | // Helper: true when focus is in a form control (don't trigger app shortcuts) |
| 17549 | function isFocusInFormControl() { |
| 17550 | const el = document.activeElement; |
| 17551 | return el && ( |
| 17552 | el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.tagName === 'SELECT' || |
| 17553 | el.isContentEditable |
| 17554 | ); |
| 17555 | } |
| 17556 | |
| 17557 | // Navigate to next/previous model in detail view (called from keydown when details visible) |
| 17558 | function navigateDetailView(direction) { |
| 17559 | const detailsPanel = document.getElementById('model-details'); |
| 17560 | if (!detailsPanel || detailsPanel.classList.contains('hidden')) return false; |
| 17561 | const items = Array.from(document.querySelectorAll('.file-item')); |
| 17562 | if (items.length === 0) return false; |
| 17563 | const currentPath = getCurrentModelFilePath() || currentModelDetailsPath || ''; |
| 17564 | const normalizedCurrent = currentPath ? normalizePathForComparison(currentPath) : ''; |
| 17565 | let index = -1; |
| 17566 | if (normalizedCurrent) { |
| 17567 | index = items.findIndex(item => { |
| 17568 | const p = item.getAttribute('data-filepath') || item.dataset.filepath || ''; |
| 17569 | return p && normalizePathForComparison(p) === normalizedCurrent; |
| 17570 | }); |
| 17571 | } |
| 17572 | if (index < 0) index = items.findIndex(item => item.classList.contains('selected')); |
| 17573 | if (index < 0) index = 0; |
| 17574 | const nextIndex = direction === 'next' ? index + 1 : index - 1; |
| 17575 | if (nextIndex < 0 || nextIndex >= items.length) return false; |
| 17576 | const target = items[nextIndex]; |
| 17577 | const filePath = target.getAttribute('data-filepath') || target.dataset.filepath; |
| 17578 | if (!filePath) return false; |
| 17579 | document.querySelectorAll('.file-item').forEach(item => item.classList.remove('selected')); |
| 17580 | target.classList.add('selected'); |
| 17581 | target.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); |
| 17582 | showModelDetails(filePath); |
| 17583 | return true; |
| 17584 | } |
| 17585 | |
| 17586 | // Handle keyboard shortcuts |
| 17587 | document.addEventListener('keydown', async (event) => { |
| 17588 | const mod = event.ctrlKey || event.metaKey; |
| 17589 | const inInput = isFocusInFormControl(); |
| 17590 | const detailsVisible = (() => { |
| 17591 | const p = document.getElementById('model-details'); |
| 17592 | return p && !p.classList.contains('hidden'); |
| 17593 | })(); |
| 17594 | |
| 17595 | // Handle Escape key to exit multi-edit mode |
| 17596 | if (event.key === 'Escape' || event.key === 'Esc') { |
| 17597 | if (isMultiSelectMode) { |
| 17598 | event.preventDefault(); |
| 17599 | exitMultiEditMode(); |
| 17600 | return; |
| 17601 | } |
| 17602 | } |
| 17603 | |
| 17604 | // Search focus: Ctrl+/ or Cmd+/ (always allow so user can jump to search from anywhere) |
| 17605 | if (mod && event.key === '/') { |
| 17606 | event.preventDefault(); |
no test coverage detected