| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @implements {WebInspector.TargetManager.Observer} | 7 * @implements {WebInspector.TargetManager.Observer} |
| 8 * @param {!WebInspector.TargetManager} targetManager | 8 * @param {!WebInspector.TargetManager} targetManager |
| 9 * @param {!WebInspector.Context} context | 9 * @param {!WebInspector.Context} context |
| 10 */ | 10 */ |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 newContext = executionContexts[0]; | 206 newContext = executionContexts[0]; |
| 207 break; | 207 break; |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 this._ignoreContextChanged = true; | 211 this._ignoreContextChanged = true; |
| 212 this._context.setFlavor(WebInspector.ExecutionContext, newContext); | 212 this._context.setFlavor(WebInspector.ExecutionContext, newContext); |
| 213 this._ignoreContextChanged = false; | 213 this._ignoreContextChanged = false; |
| 214 } | 214 } |
| 215 }; | 215 }; |
| 216 | |
| 217 /** | |
| 218 * @param {!Element} proxyElement | |
| 219 * @param {!Range} wordRange | |
| 220 * @param {boolean} force | |
| 221 * @param {function(!Array.<string>, number=)} completionsReadyCallback | |
| 222 */ | |
| 223 WebInspector.ExecutionContextSelector.completionsForTextPromptInCurrentContext =
function(proxyElement, wordRange, force, completionsReadyCallback) | |
| 224 { | |
| 225 var expressionRange = wordRange.cloneRange(); | |
| 226 expressionRange.collapse(true); | |
| 227 expressionRange.setStartBefore(proxyElement); | |
| 228 WebInspector.ExecutionContextSelector.completionsForTextInCurrentContext(exp
ressionRange.toString(), wordRange.toString(), force).then(completionsReadyCallb
ack); | |
| 229 }; | |
| 230 /** | |
| 231 * @param {string} text | |
| 232 * @param {string} completionsPrefix | |
| 233 * @param {boolean=} force | |
| 234 * @return {!Promise<!Array<string>>} | |
| 235 */ | |
| 236 WebInspector.ExecutionContextSelector.completionsForTextInCurrentContext = funct
ion(text, completionsPrefix, force) | |
| 237 { | |
| 238 var executionContext = WebInspector.context.flavor(WebInspector.ExecutionCon
text); | |
| 239 if (!executionContext) | |
| 240 return Promise.resolve([]); | |
| 241 var index; | |
| 242 var stopChars = new Set(" =:({;,!+-*/&|^<>`".split("")); | |
| 243 for (index = text.length - 1; index >= 0; index--) { | |
| 244 // Pass less stop characters to rangeOfWord so the range will be a more
complete expression. | |
| 245 if (stopChars.has(text.charAt(index))) | |
| 246 break; | |
| 247 } | |
| 248 var clippedExpression = text.substring(index + 1); | |
| 249 var bracketCount = 0; | |
| 250 | |
| 251 index = clippedExpression.length - 1; | |
| 252 while (index >= 0) { | |
| 253 var character = clippedExpression.charAt(index); | |
| 254 if (character === "]") | |
| 255 bracketCount++; | |
| 256 // Allow an open bracket at the end for property completion. | |
| 257 if (character === "[" && index < clippedExpression.length - 1) { | |
| 258 bracketCount--; | |
| 259 if (bracketCount < 0) | |
| 260 break; | |
| 261 } | |
| 262 index--; | |
| 263 } | |
| 264 clippedExpression = clippedExpression.substring(index + 1); | |
| 265 | |
| 266 return executionContext.completionsForExpression(clippedExpression, completi
onsPrefix, force); | |
| 267 }; | |
| OLD | NEW |