Skip to content

Commit

Permalink
Merge pull request #112 from jharding/49-change-behavior-of-autocomplete
Browse files Browse the repository at this point in the history
Change behavior of autocomplete
  • Loading branch information
jharding committed Mar 14, 2013
2 parents 7fd872d + 56354bb commit 6fcd112
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/typeahead_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
},

Expand Down
3 changes: 3 additions & 0 deletions test/typeahead_view_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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');
});
Expand Down Expand Up @@ -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');
});
Expand Down

0 comments on commit 6fcd112

Please sign in to comment.