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

Commit

Permalink
disable urlbar autocomplete after focus or cut
Browse files Browse the repository at this point in the history
fix #4941

Auditors: @bbondy

Test Plan:
1. go to bing.com
2. hit cmd+L (or ctrl+L, ctrl+A) to focus and select the urlbar
3. hit cmd/ctrl+X to cut the urlbar text
4. the text should disappear and not reappear
  • Loading branch information
diracdeltas committed Oct 21, 2016
1 parent 3ede178 commit 394d1e3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
21 changes: 17 additions & 4 deletions js/components/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ class UrlBar extends ImmutableComponent {
this.onFocus = this.onFocus.bind(this)
this.onBlur = this.onBlur.bind(this)
this.onKeyDown = this.onKeyDown.bind(this)
this.onChange = this.onChange.bind(this)
this.onCut = this.onCut.bind(this)
this.onKeyUp = this.onKeyUp.bind(this)
this.onClick = this.onClick.bind(this)
this.onContextMenu = this.onContextMenu.bind(this)
this.activateSearchEngine = false
this.searchSelectEntry = null
this.keyPressed = false
this.disableAutocomplete = false
this.showAutocompleteResult = debounce(() => {
if (!this.urlInput || this.keyPressed) {
if (!this.urlInput || this.keyPressed || this.disableAutocomplete) {
return
}
const suffixLen = this.props.locationValueSuffix.length
Expand Down Expand Up @@ -108,6 +110,9 @@ class UrlBar extends ImmutableComponent {
if (!this.isActive) {
windowActions.setUrlBarActive(true)
}
if (e.keyCode > 47 && e.keyCode < 112) {
this.disableAutocomplete = false
}
switch (e.keyCode) {
case KeyCodes.ENTER:
windowActions.setUrlBarActive(false)
Expand Down Expand Up @@ -162,13 +167,15 @@ class UrlBar extends ImmutableComponent {
}
break
case KeyCodes.UP:
this.disableAutocomplete = false
if (this.shouldRenderUrlBarSuggestions) {
// TODO: We shouldn't be calling into urlBarSuggestions from the parent component at all
this.urlBarSuggestions.previousSuggestion()
e.preventDefault()
}
break
case KeyCodes.DOWN:
this.disableAutocomplete = false
if (this.shouldRenderUrlBarSuggestions) {
// TODO: We shouldn't be calling into urlBarSuggestions from the parent component at all
if (!this.urlBarSuggestions.suggestionList) {
Expand Down Expand Up @@ -255,7 +262,11 @@ class UrlBar extends ImmutableComponent {
this.searchSelectEntry = null
}

onChange (e) {
onCut () {
this.disableAutocomplete = true
}

onKeyUp (e) {
switch (e.keyCode) {
case KeyCodes.UP:
case KeyCodes.DOWN:
Expand Down Expand Up @@ -294,6 +305,7 @@ class UrlBar extends ImmutableComponent {
componentWillMount () {
ipc.on(messages.SHORTCUT_FOCUS_URL, (e) => {
// If the user hits Command+L while in the URL bar they want everything suggested as the new potential URL to laod.
this.disableAutocomplete = true
this.updateLocationToSuggestion()
windowActions.setUrlBarSelected(true)
windowActions.setUrlBarActive(true)
Expand Down Expand Up @@ -452,7 +464,8 @@ class UrlBar extends ImmutableComponent {
onFocus={this.onFocus}
onBlur={this.onBlur}
onKeyDown={this.onKeyDown}
onKeyUp={this.onChange}
onCut={this.onCut}
onKeyUp={this.onKeyUp}
onClick={this.onClick}
onContextMenu={this.onContextMenu}
value={value}
Expand Down
18 changes: 17 additions & 1 deletion test/components/urlBarTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* global describe, it, beforeEach */

const Brave = require('../lib/brave')
const {urlInput} = require('../lib/selectors')
const {activeWebview, urlInput} = require('../lib/selectors')
const assert = require('assert')

describe('urlBar', function () {
function * setup (client) {
Expand Down Expand Up @@ -87,5 +88,20 @@ describe('urlBar', function () {
.then((val) => val === 'aboutx')
})
})

it('it does not change input after focus until keydown', function * () {
yield this.app.client
.keys('https://brave.com/ ')
.keys('\uE007')
.waitForElementFocus(activeWebview)
.ipcSend('shortcut-focus-url')
.getValue(urlInput).then((val) => assert(val === 'https://brave.com/'))
.keys('\uE015')
.waitUntil(function () {
return this.getValue(urlInput).then((val) => {
return val === 'https://brave.com/test'
})
})
})
})
})

1 comment on commit 394d1e3

@bbondy
Copy link
Member

@bbondy bbondy commented on 394d1e3 Oct 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.