Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Handle typing over selected suggestions
Browse files Browse the repository at this point in the history
Auditors: @aekeus

This fixes the failing test: On suggestion mouseover, appends autocomplete URLs without interrupting typing

Fix #5582
  • Loading branch information
bbondy committed Nov 14, 2016
1 parent 9feff9f commit c9d80a9
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions js/components/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,27 @@ class UrlBar extends ImmutableComponent {
this.searchSelectEntry = null
}

get suggestionLocation () {
const selectedIndex = this.activeFrame.getIn(['navbar', 'urlbar', 'suggestions', 'selectedIndex'])
if (typeof selectedIndex === 'number') {
const suggestion = this.activeFrame.getIn(['navbar', 'urlbar', 'suggestions', 'suggestionList', selectedIndex - 1])
if (suggestion) {
return suggestion.location
}
}
}

onChange (e) {
const oldActivateSearchEngine = this.activateSearchEngine
const oldSearchSelectEntry = this.searchSelectEntry

this.clearSearchEngine()
this.detectSearchEngine(e.target.value)

if (this.suggestionLocation) {
windowActions.setUrlBarSuggestions(undefined, null)
}

// TODO: activeSearchEngine and searchSelectEntry should be stored in
// state so we don't have to do this hack.
// It comes into play because no keyUp state changes happen when
Expand Down Expand Up @@ -362,12 +376,8 @@ class UrlBar extends ImmutableComponent {
!this.isActive && !this.isFocused) {
this.urlInput.value = this.locationValue
} else if (this.isActive) {
const selectedIndex = this.activeFrame.getIn(['navbar', 'urlbar', 'suggestions', 'selectedIndex'])
if (typeof selectedIndex === 'number') {
const suggestion = this.activeFrame.getIn(['navbar', 'urlbar', 'suggestions', 'suggestionList', selectedIndex - 1])
if (suggestion) {
this.urlInput.value = suggestion.location
}
if (this.suggestionLocation) {
this.urlInput.value = this.suggestionLocation
}
}
}
Expand Down

0 comments on commit c9d80a9

Please sign in to comment.