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

Commit

Permalink
Merge pull request #9613 from brave/edit-autocomplete
Browse files Browse the repository at this point in the history
Editing custom selection from autocomplete can clear URL suffix
  • Loading branch information
bsclifton committed Jun 21, 2017

Unverified

This user has not yet uploaded their public signing key.
1 parent 742e4eb commit ea77b35
Showing 2 changed files with 40 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/renderer/components/navigation/urlBar.js
Original file line number Diff line number Diff line change
@@ -269,18 +269,21 @@ class UrlBar extends React.Component {
this.lastSuffix = ''
}

const selectionStart = this.urlInput.selectionStart
const selectionEnd = this.urlInput.selectionEnd

// if there is no selection then we are not in autocomplete
// so make sure that this.lastValue is set to urlInput.value
if (this.urlInput.selectionStart === this.urlInput.selectionEnd) {
if (selectionStart === selectionEnd) {
this.lastVal = this.urlInput.value
this.lastSuffix = ''
}

const selectionStart = this.urlInput.selectionStart
const lastValueWithSuffix = this.getValue()
const newValue = [
this.lastVal.slice(0, selectionStart),
lastValueWithSuffix.slice(0, selectionStart),
String.fromCharCode(e.which),
this.lastVal.slice(this.urlInput.selectionEnd)
lastValueWithSuffix.slice(selectionEnd)
].join('')

if (!this.updateAutocomplete(newValue)) {
33 changes: 33 additions & 0 deletions test/navbar-components/urlBarTest.js
Original file line number Diff line number Diff line change
@@ -750,4 +750,37 @@ describe('urlBar tests', function () {
.waitForInputText(urlInput, this.page2Url)
})
})

describe('keeps url text separate from suffix text', function () {
Brave.beforeAll(this)
before(function * () {
yield setup(this.app.client)
yield this.app.client.waitForExist(urlInput)
yield this.app.client.waitForElementFocus(urlInput)
yield this.app.client
.onClearBrowsingData({browserHistory: true})
.addSite({ location: 'https://github.com/brave/browser-laptop', title: 'browser-laptop' })
.addSite({ location: 'https://github.com/brave/ad-block', title: 'Muon' })
})

it('changes only the selection', function * () {
yield this.app.client
.setInputText(urlInput, 'git')
.waitForSelectedText('hub.com')
// Select next suggestion
.keys(Brave.keys.DOWN)
.waitForSelectedText('hub.com/brave/browser-laptop')
// Remove selection of suffix
.keys(Brave.keys.RIGHT)
// Move to the left and create a new selection
.keys(Brave.keys.LEFT)
.keys(Brave.keys.LEFT)
.keys(Brave.keys.LEFT)
.keys(Brave.keys.SHIFT)
.keys(Brave.keys.LEFT)
.keys(Brave.keys.SHIFT)
.keys('s')
.waitForInputText(urlInput, 'github.com/brave/browser-lastop')
})
})
})

0 comments on commit ea77b35

Please sign in to comment.