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

Commit

Permalink
Editing custom selection from autocomplete can clear URL suffix
Browse files Browse the repository at this point in the history
Fix #9322
  • Loading branch information
bbondy committed Jun 20, 2017
1 parent 81f05a4 commit 28bf21b
Show file tree
Hide file tree
Showing 2 changed files with 30 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
Expand Up @@ -261,18 +261,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)) {
Expand Down
23 changes: 23 additions & 0 deletions test/navbar-components/urlBarTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,4 +752,27 @@ 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, '')
.debug()
*/
})
})
})

0 comments on commit 28bf21b

Please sign in to comment.