fix: empty server list throws console error on move (#1048)

Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
zio/stable
Kushal Niroula 2023-01-13 12:08:24 +05:45 committed by GitHub
parent 6cb3183c2e
commit 23532062f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -94,6 +94,10 @@ function toSelector(server: string) {
return server.replace(/[^\w-]/g, '-') return server.replace(/[^\w-]/g, '-')
} }
function move(delta: number) { function move(delta: number) {
if (filteredServers.length === 0) {
autocompleteIndex = 0
return
}
autocompleteIndex = ((autocompleteIndex + delta) + filteredServers.length) % filteredServers.length autocompleteIndex = ((autocompleteIndex + delta) + filteredServers.length) % filteredServers.length
document.querySelector(`#${toSelector(filteredServers[autocompleteIndex])}`)?.scrollIntoView(false) document.querySelector(`#${toSelector(filteredServers[autocompleteIndex])}`)?.scrollIntoView(false)
} }