Commit 2d5b42ff authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Chromium LUCI CQ

[realbox] Always update realbox input when a default match is present

Previously, the text selection in the realbox input was being set to
the inline autocompletion of the default match (if one existed)
assuming the current input contains the previously typed text, thus
generating the expected input.

This logic can result in undesirable outcomes where the current input
does not match the previously typed text. As of this CL no such
assumption is made and the input is updated to the previously typed
input + inline autocompletion of the default match (if applicable).

Fixed: 1152269
Change-Id: I518b2095736c8ef328c820bce2e9682f1b469aad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566296Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832206}
parent 34e3cd44
...@@ -267,11 +267,10 @@ class RealboxElement extends PolymerElement { ...@@ -267,11 +267,10 @@ class RealboxElement extends PolymerElement {
const firstMatch = hasMatches ? this.result_.matches[0] : null; const firstMatch = hasMatches ? this.result_.matches[0] : null;
if (firstMatch && firstMatch.allowedToBeDefaultMatch) { if (firstMatch && firstMatch.allowedToBeDefaultMatch) {
this.$.matches.selectFirst(); this.$.matches.selectFirst();
const inlineAutocompletion = this.updateInput_({
decodeString16(firstMatch.inlineAutocompletion); text: this.lastQueriedInput_,
if (inlineAutocompletion) { inline: decodeString16(firstMatch.inlineAutocompletion) || '',
this.updateInput_({inline: inlineAutocompletion}); });
}
// Navigate to the default up-to-date match if the user typed and pressed // Navigate to the default up-to-date match if the user typed and pressed
// 'Enter' too fast. // 'Enter' too fast.
......
...@@ -532,7 +532,12 @@ suite('NewTabPageRealboxTest', () => { ...@@ -532,7 +532,12 @@ suite('NewTabPageRealboxTest', () => {
}); });
assertEquals(1, testProxy.handler.getCallCount('queryAutocomplete')); assertEquals(1, testProxy.handler.getCallCount('queryAutocomplete'));
const matches = [createSearchMatch(), createUrlMatch()]; const matches = [
createSearchMatch({
allowedToBeDefaultMatch: true,
}),
createUrlMatch()
];
testProxy.callbackRouterRemote.autocompleteResultChanged({ testProxy.callbackRouterRemote.autocompleteResultChanged({
input: mojoString16(realbox.$.input.value.trimLeft()), input: mojoString16(realbox.$.input.value.trimLeft()),
matches, matches,
...@@ -547,6 +552,14 @@ suite('NewTabPageRealboxTest', () => { ...@@ -547,6 +552,14 @@ suite('NewTabPageRealboxTest', () => {
assertEquals(2, matchEls.length); assertEquals(2, matchEls.length);
verifyMatch(matches[0], matchEls[0]); verifyMatch(matches[0], matchEls[0]);
verifyMatch(matches[1], matchEls[1]); verifyMatch(matches[1], matchEls[1]);
// First match is selected.
assertTrue(matchEls[0].classList.contains(CLASSES.SELECTED));
assertEquals(' hello world', realbox.$.input.value);
let start = realbox.$.input.selectionStart;
let end = realbox.$.input.selectionEnd;
assertEquals('', realbox.$.input.value.substring(start, end));
}); });
test('autocomplete response with inline autocompletion', async () => { test('autocomplete response with inline autocompletion', async () => {
...@@ -578,6 +591,9 @@ suite('NewTabPageRealboxTest', () => { ...@@ -578,6 +591,9 @@ suite('NewTabPageRealboxTest', () => {
assertEquals(1, matchEls.length); assertEquals(1, matchEls.length);
verifyMatch(matches[0], matchEls[0]); verifyMatch(matches[0], matchEls[0]);
// First match is selected.
assertTrue(matchEls[0].classList.contains(CLASSES.SELECTED));
assertEquals('hello world', realbox.$.input.value); assertEquals('hello world', realbox.$.input.value);
let start = realbox.$.input.selectionStart; let start = realbox.$.input.selectionStart;
let end = realbox.$.input.selectionEnd; let end = realbox.$.input.selectionEnd;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment