| 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 WebInspector.ConsolePrompt = class extends WebInspector.Widget { | 7 WebInspector.ConsolePrompt = class extends WebInspector.Widget { |
| 8 constructor() { | 8 constructor() { |
| 9 super(); | 9 super(); |
| 10 this._addCompletionsFromHistory = true; | 10 this._addCompletionsFromHistory = true; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 if (WebInspector.ConsolePanel.instance().isShowing()) | 194 if (WebInspector.ConsolePanel.instance().isShowing()) |
| 195 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Com
mandEvaluatedInConsolePanel); | 195 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Com
mandEvaluatedInConsolePanel); |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 _enterProcessedForTest() { | 199 _enterProcessedForTest() { |
| 200 } | 200 } |
| 201 | 201 |
| 202 /** | 202 /** |
| 203 * @param {string} prefix | 203 * @param {string} prefix |
| 204 * @param {boolean=} force |
| 204 * @return {!WebInspector.SuggestBox.Suggestions} | 205 * @return {!WebInspector.SuggestBox.Suggestions} |
| 205 */ | 206 */ |
| 206 _historyCompletions(prefix) { | 207 _historyCompletions(prefix, force) { |
| 207 if (!this._addCompletionsFromHistory || !this._isCaretAtEndOfPrompt()) | 208 if (!this._addCompletionsFromHistory || !this._isCaretAtEndOfPrompt() || (!p
refix && !force)) |
| 208 return []; | 209 return []; |
| 209 var result = []; | 210 var result = []; |
| 210 var text = this.text(); | 211 var text = this.text(); |
| 211 var set = new Set(); | 212 var set = new Set(); |
| 212 var data = this._history.historyData(); | 213 var data = this._history.historyData(); |
| 213 for (var i = data.length - 1; i >= 0 && result.length < 50; --i) { | 214 for (var i = data.length - 1; i >= 0 && result.length < 50; --i) { |
| 214 var item = data[i]; | 215 var item = data[i]; |
| 215 if (!item.startsWith(text)) | 216 if (!item.startsWith(text)) |
| 216 continue; | 217 continue; |
| 217 if (set.has(item)) | 218 if (set.has(item)) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 243 for (index = lineText.length - 1; index >= 0; index--) { | 244 for (index = lineText.length - 1; index >= 0; index--) { |
| 244 if (' =:[({;,!+-*/&|^<>.'.indexOf(lineText.charAt(index)) !== -1) | 245 if (' =:[({;,!+-*/&|^<>.'.indexOf(lineText.charAt(index)) !== -1) |
| 245 break; | 246 break; |
| 246 } | 247 } |
| 247 return new WebInspector.TextRange(lineNumber, index + 1, lineNumber, columnN
umber); | 248 return new WebInspector.TextRange(lineNumber, index + 1, lineNumber, columnN
umber); |
| 248 } | 249 } |
| 249 | 250 |
| 250 /** | 251 /** |
| 251 * @param {!WebInspector.TextRange} queryRange | 252 * @param {!WebInspector.TextRange} queryRange |
| 252 * @param {!WebInspector.TextRange} substituteRange | 253 * @param {!WebInspector.TextRange} substituteRange |
| 254 * @param {boolean=} force |
| 253 * @return {!Promise<!WebInspector.SuggestBox.Suggestions>} | 255 * @return {!Promise<!WebInspector.SuggestBox.Suggestions>} |
| 254 */ | 256 */ |
| 255 _wordsWithQuery(queryRange, substituteRange) { | 257 _wordsWithQuery(queryRange, substituteRange, force) { |
| 256 var query = this._editor.text(queryRange); | 258 var query = this._editor.text(queryRange); |
| 257 var before = this._editor.text(new WebInspector.TextRange(0, 0, queryRange.s
tartLine, queryRange.startColumn)); | 259 var before = this._editor.text(new WebInspector.TextRange(0, 0, queryRange.s
tartLine, queryRange.startColumn)); |
| 258 var historyWords = this._historyCompletions(query); | 260 var historyWords = this._historyCompletions(query, force); |
| 259 return WebInspector.JavaScriptAutocomplete.completionsForTextInCurrentContex
t(before, query, true /* force */) | 261 return WebInspector.JavaScriptAutocomplete.completionsForTextInCurrentContex
t(before, query, force) |
| 260 .then(innerWordsWithQuery); | 262 .then(innerWordsWithQuery); |
| 261 /** | 263 /** |
| 262 * @param {!Array<string>} words | 264 * @param {!Array<string>} words |
| 263 * @return {!WebInspector.SuggestBox.Suggestions} | 265 * @return {!WebInspector.SuggestBox.Suggestions} |
| 264 */ | 266 */ |
| 265 function innerWordsWithQuery(words) { | 267 function innerWordsWithQuery(words) { |
| 266 return words.map(item => ({title: item})).concat(historyWords); | 268 return words.map(item => ({title: item})).concat(historyWords); |
| 267 } | 269 } |
| 268 } | 270 } |
| 269 | 271 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 return this._currentHistoryItem(); | 355 return this._currentHistoryItem(); |
| 354 } | 356 } |
| 355 | 357 |
| 356 /** | 358 /** |
| 357 * @return {string|undefined} | 359 * @return {string|undefined} |
| 358 */ | 360 */ |
| 359 _currentHistoryItem() { | 361 _currentHistoryItem() { |
| 360 return this._data[this._data.length - this._historyOffset]; | 362 return this._data[this._data.length - this._historyOffset]; |
| 361 } | 363 } |
| 362 }; | 364 }; |
| OLD | NEW |