From ea77b351d198cebe851e575b36ab9bc3dc08eae6 Mon Sep 17 00:00:00 2001 From: Brian Clifton Date: Wed, 21 Jun 2017 06:51:15 +0100 Subject: [PATCH] Merge pull request #9613 from brave/edit-autocomplete Editing custom selection from autocomplete can clear URL suffix --- app/renderer/components/navigation/urlBar.js | 11 ++++--- test/navbar-components/urlBarTest.js | 33 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/app/renderer/components/navigation/urlBar.js b/app/renderer/components/navigation/urlBar.js index 8c20cabd5a8..256364a9251 100644 --- a/app/renderer/components/navigation/urlBar.js +++ b/app/renderer/components/navigation/urlBar.js @@ -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)) { diff --git a/test/navbar-components/urlBarTest.js b/test/navbar-components/urlBarTest.js index 57e78e0cd53..1720f7f61d4 100644 --- a/test/navbar-components/urlBarTest.js +++ b/test/navbar-components/urlBarTest.js @@ -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') + }) + }) })