diff options
| author | Alon Levy <alon@pobox.com> | 2014-11-25 22:05:58 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-11-25 22:06:01 +0200 |
| commit | c6d89b9f4457456397dcc958cc4b90cfa5196376 (patch) | |
| tree | a08bcdf65af7f263526ce617dbc5a8f6976042c0 /src/textanalysis.js | |
| parent | 518957e1ef1244cb9fbb017b742ff01da56dd79f (diff) | |
Fixes #102 - autocomplete with spaces
Possibly introduces required double enters sometimes. This is a result
of an exception thrown in the callback, needs work.
Diffstat (limited to 'src/textanalysis.js')
| -rw-r--r-- | src/textanalysis.js | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/textanalysis.js b/src/textanalysis.js index e80ce0a8..e2d1735a 100644 --- a/src/textanalysis.js +++ b/src/textanalysis.js @@ -22,11 +22,24 @@ function selectedType() function autoSuggestAddName(name) { /* note that name can contain spaces - this is ok. We might want to limit this though? */ - if(name.split(" ").length > 1) { - sugg['"' + name + '"'] = 1; - } else { - sugg[name] = 1; + sugg[name] = 1; +} + +function unquoted(name) +{ + var start = 0, + end = name.length; + + if (name.length >= 1) { + if (name.charAt(0) == '"') { + start = 1; + if (name.length > 1 && name.charAt(name.length - 1) == '"') { + end = name.length - 1; + } + } + return name.substring(start, end); } + return name; } function autocompleteCallback(request, response_callback) @@ -34,7 +47,7 @@ function autocompleteCallback(request, response_callback) var ret = []; if (request.term === "" || request.term) { for (var name in sugg) { - if (name.toLowerCase().indexOf(request.term.toLowerCase()) === 0) { + if (name.toLowerCase().indexOf(unquoted(request.term.toLowerCase())) === 0) { ret.push(name); } } |
