Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 * @return {!Array<string>} | 237 * @return {!Array<string>} |
| 238 */ | 238 */ |
| 239 WebInspector.JavaScriptAutocomplete._completionsForPrefix = function(dotNotation , bracketNotation, expressionString, prefix, properties) { | 239 WebInspector.JavaScriptAutocomplete._completionsForPrefix = function(dotNotation , bracketNotation, expressionString, prefix, properties) { |
| 240 if (bracketNotation) { | 240 if (bracketNotation) { |
| 241 if (prefix.length && prefix[0] === '\'') | 241 if (prefix.length && prefix[0] === '\'') |
| 242 var quoteUsed = '\''; | 242 var quoteUsed = '\''; |
| 243 else | 243 else |
| 244 var quoteUsed = '"'; | 244 var quoteUsed = '"'; |
| 245 } | 245 } |
| 246 | 246 |
| 247 var results = []; | 247 var caseSensitivePrefix = []; |
|
lushnikov
2016/11/03 22:06:51
let's move this to where we use these
einbinder
2016/11/03 23:12:14
Done.
| |
| 248 var caseInsensitivePrefix = []; | |
| 249 var caseSensitiveAnywhere = []; | |
| 250 var caseInsensitiveAnywhere = []; | |
| 248 | 251 |
| 249 if (!expressionString) { | 252 if (!expressionString) { |
| 250 const keywords = [ | 253 const keywords = [ |
| 251 'break', 'case', 'catch', 'continue', 'default', 'delete', 'do', 'else', ' finally', | 254 'break', 'case', 'catch', 'continue', 'default', 'delete', 'do', 'else', ' finally', |
| 252 'for', 'function', 'if', 'in', 'instanceof', 'new', 'return', 'switch', 't his', | 255 'for', 'function', 'if', 'in', 'instanceof', 'new', 'return', 'switch', 't his', |
| 253 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with' | 256 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with' |
| 254 ]; | 257 ]; |
| 255 properties = properties.concat(keywords); | 258 properties = properties.concat(keywords); |
| 256 } | 259 } |
| 257 | 260 |
| 258 properties.sort(); | 261 properties.sort(); |
| 259 | 262 |
| 260 for (var i = 0; i < properties.length; ++i) { | 263 for (var i = 0; i < properties.length; ++i) { |
| 261 var property = properties[i]; | 264 var property = properties[i]; |
| 262 | 265 |
| 263 // Assume that all non-ASCII characters are letters and thus can be used as part of identifier. | 266 // Assume that all non-ASCII characters are letters and thus can be used as part of identifier. |
| 264 if (dotNotation && !/^[a-zA-Z_$\u008F-\uFFFF][a-zA-Z0-9_$\u008F-\uFFFF]*$/.t est(property)) | 267 if (dotNotation && !/^[a-zA-Z_$\u008F-\uFFFF][a-zA-Z0-9_$\u008F-\uFFFF]*$/.t est(property)) |
| 265 continue; | 268 continue; |
| 266 | 269 |
| 267 if (bracketNotation) { | 270 if (bracketNotation) { |
| 268 if (!/^[0-9]+$/.test(property)) | 271 if (!/^[0-9]+$/.test(property)) |
| 269 property = quoteUsed + property.escapeCharacters(quoteUsed + '\\') + quo teUsed; | 272 property = quoteUsed + property.escapeCharacters(quoteUsed + '\\') + quo teUsed; |
| 270 property += ']'; | 273 property += ']'; |
| 271 } | 274 } |
| 272 | 275 |
| 273 if (property.length < prefix.length) | 276 if (property.length < prefix.length) |
| 274 continue; | 277 continue; |
| 275 if (prefix.length && !property.startsWith(prefix)) | 278 if (prefix.length && property.toLowerCase().indexOf(prefix.toLowerCase()) == = -1) |
| 276 continue; | 279 continue; |
| 280 // Substitute actual newlines with newline characters. @see crbug.com/498421 | |
| 281 var prop = property.split('\n').join('\\n'); | |
| 277 | 282 |
| 278 // Substitute actual newlines with newline characters. @see crbug.com/498421 | 283 if (property.startsWith(prefix)) |
| 279 results.push(property.split('\n').join('\\n')); | 284 caseSensitivePrefix.push(prop); |
| 285 else if (property.toLowerCase().startsWith(prefix.toLowerCase())) | |
| 286 caseInsensitivePrefix.push(prop); | |
| 287 else if (property.indexOf(prefix) !== -1) | |
| 288 caseSensitiveAnywhere.push(prop); | |
| 289 else | |
| 290 caseInsensitiveAnywhere.push(prop); | |
| 280 } | 291 } |
|
lushnikov
2016/11/03 22:06:51
I'm not convinced about JS case-insensetive autoco
einbinder
2016/11/03 23:12:14
Yay!
| |
| 281 return results; | 292 return caseSensitivePrefix.concat(caseInsensitivePrefix).concat(caseSensitiveA nywhere).concat(caseInsensitiveAnywhere); |
| 282 }; | 293 }; |
| OLD | NEW |