diff --git a/src/webview/script.ts b/src/webview/script.ts index f08a1c2..6f51993 100644 --- a/src/webview/script.ts +++ b/src/webview/script.ts @@ -412,6 +412,24 @@ type SearchMatchWithId = SearchMatch & { matchId: number, icon?: FileSearchResul // @ts-ignore window.selectMatchById = selectMatchById; + function selectFirstMatchInNextFile() { + if (allMatches.length === 0) return; + + if (selectedMatchIndex < 0) { + selectMatchById(0); + return; + } + + const currentFile = allMatches[selectedMatchIndex].relativePath; + + for (let i = selectedMatchIndex + 1; i < allMatches.length; i++) { + if (allMatches[i].relativePath !== currentFile) { + selectMatchById(allMatches[i].matchId); + return; + } + } + } + function openMatchById(matchId: number, event?: MouseEvent) { if (matchId < 0 || matchId >= allMatches.length) return; @@ -670,7 +688,9 @@ type SearchMatchWithId = SearchMatch & { matchId: number, icon?: FileSearchResul // Arrow key navigation - works even when in search input if (e.key === 'ArrowDown' && !isInOtherInput) { e.preventDefault(); - if (selectedMatchIndex < allMatches.length - 1) { + if (e.ctrlKey || e.metaKey) { + selectFirstMatchInNextFile(); + } else if (selectedMatchIndex < allMatches.length - 1) { selectMatchById(selectedMatchIndex + 1); } } else if (e.key === 'ArrowUp' && !isInOtherInput) { @@ -701,4 +721,4 @@ type SearchMatchWithId = SearchMatch & { matchId: number, icon?: FileSearchResul }); searchInput.focus(); -}()); \ No newline at end of file +}());