From c457a0c4e8bb80cbc65bac0a3405d04920e117c4 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Wed, 21 Jun 2017 00:38:06 +0200 Subject: [PATCH] Fixed endless loop on hints with same length. In case hints with same length where generated the loop to get the number of addressable hints did not end when there was only one single hintkey defined. So now do not attempt to run the same length hint label logic in case there is only one hint key set. In this case normal hint labels are generated. --- src/scripts/hints.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/scripts/hints.js b/src/scripts/hints.js index 7482ffc..6f5b6f5 100644 --- a/src/scripts/hints.js +++ b/src/scripts/hints.js @@ -237,9 +237,9 @@ var hints = Object.freeze((function(){ return (len > 0) ? (config.hintKeys.length ** len) : 0; } - function getMaxHints(maxlen) { - var res = 0, - len = maxlen; + /* Calculate the number of addressable hints for given label length. */ + function getMaxHints(len) { + var res = 0; while (len > 0) { res += getMaxHintsSameLength(len); @@ -254,17 +254,19 @@ var hints = Object.freeze((function(){ n = 0, matcher = getMatcher(filterText); - if (config.keysSameLength) { + /* We can generate same length label if there is only one hint key */ + /* except in case there is only one hint. But we don't need to */ + /* handle this. */ + if (config.keysSameLength && config.hintKeys.length > 1) { /* get number of hints to be shown */ - var hintCount = 0; + var hintCount = 0, hintStringLen = 1; for (i = 0; i < hints.length; i++) { if (matcher(hints[i].text)) { hintCount++; } } - /* find hint string length to describe all hints with same length */ - var hintStringLen = 1; + /* Find hint string length to describe all hints with same length. */ while (getMaxHintsSameLength(hintStringLen) < hintCount) { hintStringLen++; } -- 2.20.1