Keep active hint focused if it's still valid (#53).
authorDaniel Carl <danielcarl@gmx.de>
Thu, 19 Dec 2013 18:10:09 +0000 (19:10 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Thu, 19 Dec 2013 18:11:21 +0000 (19:11 +0100)
If a hint is focussed and later filter will keep it valid, the hint also keeps
focussed.

src/hints.js

index 0730c6b..590163e 100644 (file)
@@ -231,7 +231,7 @@ var VbHint = (function(){
     }
 
     function show() {
-        var i, hint,
+        var i, hint, newIdx,
             num     = 1,
             matcher = getMatcher(filterText);
 
@@ -261,7 +261,11 @@ var VbHint = (function(){
 
             return fire();
         }
-        return focusHint(0);
+
+        /* if the previous active hint isn't valid set focus to first */
+        if (!activeHint || validHints.indexOf(activeHint) < 0) {
+            return focusHint(0);
+        }
     }
 
     /* Returns a validator method to check if the hint elements text matches */