Commit 10146490 authored by Joel Einbinder's avatar Joel Einbinder Committed by Commit Bot

DevTools: Select exact matches before other items in autocomplete.

This makes sure that if the user types in a property exactly, it will
always be the default selected suggested item.

Bug: 879351
Change-Id: I4425e105ff9381e164b3455f5e727c28e3b2d931
Reviewed-on: https://chromium-review.googlesource.com/1211862
Commit-Queue: Joel Einbinder <einbinder@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589358}
parent f6f1f191
......@@ -258,4 +258,9 @@ Checking 'thePrefix'
Found: thePrefix
Found: thePrefixAndTheSuffix
Checking 'objWithMethod.method'
Found: method
Found: methodWithSuffix
Default suggestion: method
......@@ -36,6 +36,11 @@
}
var thePrefix = true;
var thePrefixAndTheSuffix = true;
class ClassWithMethod {
method(){}
}
const objWithMethod = new ClassWithMethod();
objWithMethod.methodWithSuffix = true;
`);
var consoleEditor;
......@@ -44,8 +49,9 @@
* @param {string} text
* @param {!Array<string>} expected
* @param {boolean=} force
* @param {boolean=} reportDefault
*/
async function testCompletions(text, expected, force) {
async function testCompletions(text, expected, force, reportDefault) {
var cursorPosition = text.indexOf('|');
if (cursorPosition < 0)
......@@ -87,6 +93,14 @@
}
}
if (reportDefault) {
const defaultSuggestion = suggestions.reduce((a, b) => (a.priority || 0) >= (b.priority || 0) ? a : b);
if (defaultSuggestion.title)
TestRunner.addResult(`Default suggestion: ${defaultSuggestion.text}, displayed as ${defaultSuggestion.title}`);
else
TestRunner.addResult(`Default suggestion: ${defaultSuggestion.text}`);
}
if (await TestRunner.evaluateInPagePromise('cantTouchThis') !== false) {
TestRunner.addResult('ERROR! Side effects were detected!');
await TestRunner.evaluateInPagePromise('cantTouchThis = false');
......@@ -205,5 +219,6 @@
() => testCompletions(
'shouldNot|FindThisFunction()', ['shouldNotFindThisFunction']),
() => testCompletions('thePrefix', ['thePrefix', 'thePrefixAndTheSuffix']),
() => testCompletions('objWithMethod.method', ['method', 'methodWithSuffix'], false, true),
]).then(TestRunner.completeTest);
})();
......@@ -559,7 +559,7 @@ ObjectUI.JavaScriptAutocomplete = class {
allProperties.add(property);
if (property.startsWith(query))
caseSensitivePrefix.push({text: property, priority: 4});
caseSensitivePrefix.push({text: property, priority: property === query ? 5 : 4});
else if (lowerCaseProperty.startsWith(lowerCaseQuery))
caseInsensitivePrefix.push({text: property, priority: 3});
else if (property.indexOf(query) !== -1)
......
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