diff options
| author | Alon Levy <alon@pobox.com> | 2014-12-06 12:19:50 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-12-06 12:19:50 +0200 |
| commit | 1a16eb234dae2dfd494072c7e9b536d8f6a61dc1 (patch) | |
| tree | 2b53e1080f2ffbc24cf49acd5de4b1e99f2c0830 /src/view | |
| parent | f62a7ebf668bd477e03d6bb301f9808920943909 (diff) | |
completer: add minimum_length = 1
Diffstat (limited to 'src/view')
| -rw-r--r-- | src/view/completer.js | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/view/completer.js b/src/view/completer.js index 3e4c42dd..5af9d2fb 100644 --- a/src/view/completer.js +++ b/src/view/completer.js @@ -33,7 +33,8 @@ var completer = (function (input_element, dropdown) { selected_index = -1, input_element_raw = input_element[0], completion_start = 0, - completion_end = 0; + completion_end = 0, + minimum_length = 1; // turn off the browser's autocomplete input_element.attr('autocomplete', 'off'); @@ -78,16 +79,20 @@ var completer = (function (input_element, dropdown) { if (space < cursor) { return; } + completion_start = hash + 1; + completion_end = space; + var string = text.slice(completion_start, completion_end); + if (string.length < minimum_length) { + return; + } // [hash] [cursor] [space/end] - completions(text.slice(hash + 1, space)).forEach(function(name) { + completions(string).forEach(function(name) { dropdown.append($('<div class="suggestion-item">' + name + '</div>')); }); dropdown.children().each(function (index, elem) { elem.onclick = function() { _applySuggestion(index); }; input_element.focus(); }); - completion_start = hash + 1; - completion_end = space; if (dropdown.children().length > 0) { dropdown.show(); } |
