From 61bdaa0ae87ed88d05288b1f5fd09f0b4488249b Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 18 Apr 2019 17:51:41 +0200 Subject: [PATCH] remote-browser: hitting a letter to select a file based on its name was looping on the first two matches only --- CHANGELOG.md | 1 + src/client/app/ui/utils.js | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7631995..b559e830 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - bug fixes - bottom horizontal scrollbar not responding on small screens + - remote file browser: hitting a letter to select a file based on its name was looping on the first two matches only - widgets - `logScale` can be set to a number to use a logarithm base different from the default - knob: `compact` mode is back diff --git a/src/client/app/ui/utils.js b/src/client/app/ui/utils.js index 571418e3..6f626ea6 100644 --- a/src/client/app/ui/utils.js +++ b/src/client/app/ui/utils.js @@ -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){