diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-03-28 16:25:23 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-03-28 16:25:23 +0100 |
| commit | a8cfefc602a43753353940816633daae3e1692aa (patch) | |
| tree | dea6f928b639777070c9bd9c9a3d7cc8cbfea9a4 /scraper/client/common/autocomplete.component.js | |
| parent | b94cad3271d8269b5965d0096ce5564abed9ad53 (diff) | |
abstract into citationList component
Diffstat (limited to 'scraper/client/common/autocomplete.component.js')
| -rw-r--r-- | scraper/client/common/autocomplete.component.js | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/scraper/client/common/autocomplete.component.js b/scraper/client/common/autocomplete.component.js index e6c638eb..67dc78c9 100644 --- a/scraper/client/common/autocomplete.component.js +++ b/scraper/client/common/autocomplete.component.js @@ -91,14 +91,12 @@ class Autocomplete extends Component { e.preventDefault() this.handleCancel() break - case 37: // left case 38: // up e.preventDefault() this.setState({ selected: (this.state.matches.length + this.state.selected - 1) % this.state.matches.length }) return false - case 39: // right case 40: // down e.preventDefault() this.setState({ @@ -111,7 +109,12 @@ class Autocomplete extends Component { this.handleSelect(name, true) return false case 9: // tab - keep the unverified text - this.handleSelect(this.state.q, false) + name = this.state.matches[this.state.selected] + if (name === this.state.q) { + this.handleSelect(this.state.q, true) + } else { + this.handleSelect(this.state.q, false) + } return false default: break @@ -132,7 +135,6 @@ class Autocomplete extends Component { return } let seen = {} - let matches = [] value.split(' ').forEach(word => { const re = new RegExp(word) this.index.forEach(([synonym, term]) => { @@ -150,14 +152,14 @@ class Autocomplete extends Component { } } }) - matches = Object.keys(seen) - .map(term => [seen[term], term]) - .sort((a, b) => { - return b[0] - a[0] - }) - .slice(0, 100) - .map(pair => pair[1]) }) + let matches = Object.keys(seen) + .map(term => [seen[term], term]) + .sort((a, b) => { + return b[0] - a[0] + }) + .slice(0, 100) + .map(pair => pair[1]) this.setState({ q, selected: 0, |
