remote-browser: hitting a letter to select a file based on its name was looping on the first two matches only

This commit is contained in:
jean-emmanuel 2019-04-18 17:51:41 +02:00
parent b2153b9df4
commit 61bdaa0ae8
2 changed files with 16 additions and 3 deletions

View file

@ -245,14 +245,26 @@ module.exports = {
list.childNodes[0].firstElementChild.checked = true
submit()
} else if (e.key.length === 1) {
var letter = e.key.toLowerCase()
var letter = e.key.toLowerCase(),
current = DOM.get(list, ':checked')[0],
minIndex = -1,
index = -1
if (current) minIndex = DOM.index(current.parentNode)
for (let i in files) {
if (files[i].name[0].toLowerCase() === letter && !list.childNodes[i].firstElementChild.checked) {
list.childNodes[i].firstElementChild.click()
list.childNodes[i].firstElementChild.focus()
if (index === -1) index = i
if (minIndex !== -1 && i < minIndex) continue
index = i
break
}
}
if (index !== -1) {
list.childNodes[index].firstElementChild.click()
list.childNodes[index].firstElementChild.focus()
}
}
}
function keyUpHandler(e){