Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/JavaScriptAutocomplete.js

Issue 2474143002: DevTools: Rename prefix to query in the context of autocomplete (Closed)
Patch Set: merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 WebInspector.JavaScriptAutocomplete = {}; 5 WebInspector.JavaScriptAutocomplete = {};
6 6
7 /** 7 /**
8 * @param {!Element} proxyElement 8 * @param {!Element} proxyElement
9 * @param {!Range} wordRange 9 * @param {!Range} wordRange
10 * @param {boolean} force 10 * @param {boolean} force
11 * @param {function(!Array.<string>, number=)} completionsReadyCallback 11 * @param {function(!Array.<string>, number=)} completionsReadyCallback
12 */ 12 */
13 WebInspector.JavaScriptAutocomplete.completionsForTextPromptInCurrentContext = f unction(proxyElement, wordRange, force, completionsReadyCallback) { 13 WebInspector.JavaScriptAutocomplete.completionsForTextPromptInCurrentContext = f unction(proxyElement, wordRange, force, completionsReadyCallback) {
14 var expressionRange = wordRange.cloneRange(); 14 var expressionRange = wordRange.cloneRange();
15 expressionRange.collapse(true); 15 expressionRange.collapse(true);
16 expressionRange.setStartBefore(proxyElement); 16 expressionRange.setStartBefore(proxyElement);
17 WebInspector.JavaScriptAutocomplete.completionsForTextInCurrentContext(express ionRange.toString(), wordRange.toString(), force) 17 WebInspector.JavaScriptAutocomplete.completionsForTextInCurrentContext(express ionRange.toString(), wordRange.toString(), force)
18 .then(completionsReadyCallback); 18 .then(completionsReadyCallback);
19 }; 19 };
20 20
21 /** 21 /**
22 * @param {string} text 22 * @param {string} text
23 * @param {string} completionsPrefix 23 * @param {string} query
24 * @param {boolean=} force 24 * @param {boolean=} force
25 * @return {!Promise<!Array<string>>} 25 * @return {!Promise<!Array<string>>}
26 */ 26 */
27 WebInspector.JavaScriptAutocomplete.completionsForTextInCurrentContext = functio n(text, completionsPrefix, force) { 27 WebInspector.JavaScriptAutocomplete.completionsForTextInCurrentContext = functio n(text, query, force) {
28 var index; 28 var index;
29 var stopChars = new Set(' =:({;,!+-*/&|^<>`'.split('')); 29 var stopChars = new Set(' =:({;,!+-*/&|^<>`'.split(''));
30 for (index = text.length - 1; index >= 0; index--) { 30 for (index = text.length - 1; index >= 0; index--) {
31 // Pass less stop characters to rangeOfWord so the range will be a more comp lete expression. 31 // Pass less stop characters to rangeOfWord so the range will be a more comp lete expression.
32 if (stopChars.has(text.charAt(index))) 32 if (stopChars.has(text.charAt(index)))
33 break; 33 break;
34 } 34 }
35 var clippedExpression = text.substring(index + 1); 35 var clippedExpression = text.substring(index + 1);
36 var bracketCount = 0; 36 var bracketCount = 0;
37 37
38 index = clippedExpression.length - 1; 38 index = clippedExpression.length - 1;
39 while (index >= 0) { 39 while (index >= 0) {
40 var character = clippedExpression.charAt(index); 40 var character = clippedExpression.charAt(index);
41 if (character === ']') 41 if (character === ']')
42 bracketCount++; 42 bracketCount++;
43 // Allow an open bracket at the end for property completion. 43 // Allow an open bracket at the end for property completion.
44 if (character === '[' && index < clippedExpression.length - 1) { 44 if (character === '[' && index < clippedExpression.length - 1) {
45 bracketCount--; 45 bracketCount--;
46 if (bracketCount < 0) 46 if (bracketCount < 0)
47 break; 47 break;
48 } 48 }
49 index--; 49 index--;
50 } 50 }
51 clippedExpression = clippedExpression.substring(index + 1); 51 clippedExpression = clippedExpression.substring(index + 1);
52 52
53 return WebInspector.JavaScriptAutocomplete.completionsForExpression(clippedExp ression, completionsPrefix, force); 53 return WebInspector.JavaScriptAutocomplete.completionsForExpression(clippedExp ression, query, force);
54 }; 54 };
55 55
56 56
57 /** 57 /**
58 * @param {string} expressionString 58 * @param {string} expressionString
59 * @param {string} prefix 59 * @param {string} prefix
60 * @param {boolean=} force 60 * @param {boolean=} force
61 * @return {!Promise<!Array<string>>} 61 * @return {!Promise<!Array<string>>}
62 */ 62 */
63 WebInspector.JavaScriptAutocomplete.completionsForExpression = function(expressi onString, prefix, force) { 63 WebInspector.JavaScriptAutocomplete.completionsForExpression = function(expressi onString, prefix, force) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 if (property.length < prefix.length) 273 if (property.length < prefix.length)
274 continue; 274 continue;
275 if (prefix.length && !property.startsWith(prefix)) 275 if (prefix.length && !property.startsWith(prefix))
276 continue; 276 continue;
277 277
278 // Substitute actual newlines with newline characters. @see crbug.com/498421 278 // Substitute actual newlines with newline characters. @see crbug.com/498421
279 results.push(property.split('\n').join('\\n')); 279 results.push(property.split('\n').join('\\n'));
280 } 280 }
281 return results; 281 return results;
282 }; 282 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698