diff --git a/src/typeahead_view.js b/src/typeahead_view.js index 194da7ae..cec680a3 100644 --- a/src/typeahead_view.js +++ b/src/typeahead_view.js @@ -239,7 +239,7 @@ var TypeaheadView = (function() { }, _autocomplete: function(e) { - var isCursorAtEnd, ignoreEvent, query, hint; + var isCursorAtEnd, ignoreEvent, query, hint, suggestion; if (e.type === 'rightKeyed' || e.type === 'leftKeyed') { isCursorAtEnd = this.inputView.isCursorAtEnd(); @@ -253,7 +253,8 @@ var TypeaheadView = (function() { hint = this.inputView.getHintValue(); if (hint !== '' && query !== hint) { - this.inputView.setInputValue(hint); + suggestion = this.dropdownView.getFirstSuggestion(); + this.inputView.setInputValue(suggestion.value); } }, diff --git a/test/typeahead_view_spec.js b/test/typeahead_view_spec.js index c9c004c3..bf80cfd6 100644 --- a/test/typeahead_view_spec.js +++ b/test/typeahead_view_spec.js @@ -361,6 +361,7 @@ describe('TypeaheadView', function() { beforeEach(function() { this.inputView.getQuery.andReturn('app'); this.inputView.getHintValue.andReturn('apple'); + this.dropdownView.getFirstSuggestion.andReturn({ value: 'apple' }); this.inputView.trigger('tabKeyed', this.$e); }); @@ -379,6 +380,7 @@ describe('TypeaheadView', function() { beforeEach(function() { this.inputView.getQuery.andReturn('app'); this.inputView.getHintValue.andReturn('apple'); + this.dropdownView.getFirstSuggestion.andReturn({ value: 'apple' }); this.inputView.isCursorAtEnd.andReturn(true); this.inputView.getLanguageDirection.andReturn('ltr'); }); @@ -424,6 +426,7 @@ describe('TypeaheadView', function() { beforeEach(function() { this.inputView.getQuery.andReturn('app'); this.inputView.getHintValue.andReturn('apple'); + this.dropdownView.getFirstSuggestion.andReturn({ value: 'apple' }); this.inputView.isCursorAtEnd.andReturn(true); this.inputView.getLanguageDirection.andReturn('ltr'); });