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

Commit 567bd73

Browse files
committed
Fix URL bar autocomplete flashing as you type
Fix #6644 Auditors: @bsclifton
1 parent 548e28a commit 567bd73

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Changelog
22

33
## [0.13.0](https://github.com/brave/browser-laptop/releases/v0.13.0dev)
4-
- Linux sandbox added. ([#874])
5-
- Window renderer processes no longer include Node, content renderer never did in Brave. ([#6454])
4+
- Linux sandbox added. ([#874](https://github.com/brave/browser-laptop/issues/874))
5+
- Window renderer processes no longer include Node, content renderer never did in Brave. ([#6454](https://github.com/brave/browser-laptop/issues/6454))
6+
- URL bar autocomplete no longer flashes when you enter text. ([#6644](https://github.com/brave/browser-laptop/issues/6644))
67
- Muon updated to 2.0.10.
78
- Chromium updated to 54.0.2840.100.
89

app/renderer/components/urlBar.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class UrlBar extends ImmutableComponent {
3232
this.onKeyDown = this.onKeyDown.bind(this)
3333
this.onKeyUp = this.onKeyUp.bind(this)
3434
this.onChange = this.onChange.bind(this)
35+
this.onKeyPress = this.onKeyPress.bind(this)
3536
this.onClick = this.onClick.bind(this)
3637
this.onContextMenu = this.onContextMenu.bind(this)
3738
this.keyPressed = false
@@ -295,6 +296,22 @@ class UrlBar extends ImmutableComponent {
295296
}
296297
}
297298

299+
onKeyPress (e) {
300+
// If we're just continuing an autocomplete then prevent a change event
301+
const last = this.lastVal + this.lastSuffix
302+
const newValue = this.lastVal + String.fromCharCode(e.which)
303+
if (last.startsWith(newValue)) {
304+
const newSuffix = last.substring(newValue.length)
305+
this.setValue(newValue, newSuffix)
306+
windowActions.setNavBarUserInput(newValue)
307+
this.urlInput.setSelectionRange(newValue.length, newValue.length + newSuffix.length + 1)
308+
if (this.suggestionLocation) {
309+
windowActions.setUrlBarSuggestions(undefined, null)
310+
}
311+
e.preventDefault()
312+
}
313+
}
314+
298315
onChange (e) {
299316
this.setValue(e.target.value)
300317
if (this.suggestionLocation) {
@@ -306,7 +323,11 @@ class UrlBar extends ImmutableComponent {
306323
// part was set for the value.
307324
setValue (val, suffix) {
308325
this.lastVal = val
309-
this.urlInput.value = val + (suffix || '')
326+
this.lastSuffix = suffix
327+
const newValue = val + (suffix || '')
328+
if (this.urlInput.value !== newValue) {
329+
this.urlInput.value = newValue
330+
}
310331
}
311332

312333
onKeyUp (e) {
@@ -488,6 +509,7 @@ class UrlBar extends ImmutableComponent {
488509
onKeyDown={this.onKeyDown}
489510
onKeyUp={this.onKeyUp}
490511
onChange={this.onChange}
512+
onKeyPress={this.onKeyPress}
491513
onClick={this.onClick}
492514
onContextMenu={this.onContextMenu}
493515
data-l10n-id='urlbar'

test/components/navigationBarTest.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -902,20 +902,13 @@ describe('navigationBar tests', function () {
902902
})
903903

904904
it('urlbar shows webview url when focused', function * () {
905-
var page1 = this.page1
906905
yield blur(this.app.client)
907-
yield this.app.client.waitUntil(function () {
908-
return this.isExisting(urlInput).then((exists) => exists === false)
909-
})
910906
yield this.app.client
907+
.waitForElementCount(urlInput, 0)
911908
.ipcSend('shortcut-focus-url')
912-
yield this.app.client.waitUntil(function () {
913-
return this.getValue(urlInput).then((val) => val === page1)
914-
})
915-
yield this.app.client.keys('abc')
916-
yield this.app.client.waitUntil(function () {
917-
return this.getValue(urlInput).then((val) => val === 'abc')
918-
})
909+
.waitForInputText(urlInput, this.page1)
910+
.keys('zzz')
911+
.waitForInputText(urlInput, 'zzz')
919912
})
920913
})
921914

0 commit comments

Comments
 (0)