| 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; |
| 11 this._history = new WebInspector.ConsoleHistoryManager(); | 11 this._history = new WebInspector.ConsoleHistoryManager(); |
| 12 | 12 |
| 13 this._initialText = ''; | 13 this._initialText = ''; |
| 14 this._editor = null; | 14 this._editor = null; |
| 15 | 15 |
| 16 this.element.tabIndex = 0; | 16 this.element.tabIndex = 0; |
| 17 | 17 |
| 18 self.runtime.extension(WebInspector.TextEditorFactory).instance().then(gotFa
ctory.bind(this)); | 18 self.runtime.extension(WebInspector.TextEditorFactory).instance().then(gotFa
ctory.bind(this)); |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * @param {!WebInspector.TextEditorFactory} factory | 21 * @param {!WebInspector.TextEditorFactory} factory |
| 22 * @this {WebInspector.ConsolePrompt} | 22 * @this {WebInspector.ConsolePrompt} |
| 23 */ | 23 */ |
| 24 function gotFactory(factory) { | 24 function gotFactory(factory) { |
| 25 this._editor = | 25 this._editor = |
| 26 factory.createEditor({lineNumbers: false, lineWrapping: true, mimeType
: 'javascript', autoHeight: true}); | 26 factory.createEditor({lineNumbers: false, lineWrapping: true, mimeType
: 'javascript', autoHeight: true}); |
| 27 | 27 |
| 28 this._editor.configureAutocomplete({ | 28 this._editor.configureAutocomplete({ |
| 29 substituteRangeCallback: this._substituteRange.bind(this), | 29 substituteRangeCallback: this._substituteRange.bind(this), |
| 30 suggestionsCallback: this._wordsWithPrefix.bind(this), | 30 suggestionsCallback: this._wordsWithQuery.bind(this), |
| 31 captureEnter: true | 31 captureEnter: true |
| 32 }); | 32 }); |
| 33 this._editor.widget().element.addEventListener('keydown', this._editorKeyD
own.bind(this), true); | 33 this._editor.widget().element.addEventListener('keydown', this._editorKeyD
own.bind(this), true); |
| 34 this._editor.widget().show(this.element); | 34 this._editor.widget().show(this.element); |
| 35 | 35 |
| 36 this.setText(this._initialText); | 36 this.setText(this._initialText); |
| 37 delete this._initialText; | 37 delete this._initialText; |
| 38 if (this.hasFocus()) | 38 if (this.hasFocus()) |
| 39 this.focus(); | 39 this.focus(); |
| 40 this.element.tabIndex = -1; | 40 this.element.tabIndex = -1; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 var lineText = this._editor.line(lineNumber); | 241 var lineText = this._editor.line(lineNumber); |
| 242 var index; | 242 var index; |
| 243 for (index = lineText.length - 1; index >= 0; index--) { | 243 for (index = lineText.length - 1; index >= 0; index--) { |
| 244 if (' =:[({;,!+-*/&|^<>.'.indexOf(lineText.charAt(index)) !== -1) | 244 if (' =:[({;,!+-*/&|^<>.'.indexOf(lineText.charAt(index)) !== -1) |
| 245 break; | 245 break; |
| 246 } | 246 } |
| 247 return new WebInspector.TextRange(lineNumber, index + 1, lineNumber, columnN
umber); | 247 return new WebInspector.TextRange(lineNumber, index + 1, lineNumber, columnN
umber); |
| 248 } | 248 } |
| 249 | 249 |
| 250 /** | 250 /** |
| 251 * @param {!WebInspector.TextRange} prefixRange | 251 * @param {!WebInspector.TextRange} queryRange |
| 252 * @param {!WebInspector.TextRange} substituteRange | 252 * @param {!WebInspector.TextRange} substituteRange |
| 253 * @return {!Promise<!WebInspector.SuggestBox.Suggestions>} | 253 * @return {!Promise<!WebInspector.SuggestBox.Suggestions>} |
| 254 */ | 254 */ |
| 255 _wordsWithPrefix(prefixRange, substituteRange) { | 255 _wordsWithQuery(queryRange, substituteRange) { |
| 256 var prefix = this._editor.text(prefixRange); | 256 var query = this._editor.text(queryRange); |
| 257 var before = this._editor.text(new WebInspector.TextRange(0, 0, prefixRange.
startLine, prefixRange.startColumn)); | 257 var before = this._editor.text(new WebInspector.TextRange(0, 0, queryRange.s
tartLine, queryRange.startColumn)); |
| 258 var historyWords = this._historyCompletions(prefix); | 258 var historyWords = this._historyCompletions(query); |
| 259 return WebInspector.JavaScriptAutocomplete.completionsForTextInCurrentContex
t(before, prefix, true /* force */) | 259 return WebInspector.JavaScriptAutocomplete.completionsForTextInCurrentContex
t(before, query, true /* force */) |
| 260 .then(innerWordsWithPrefix); | 260 .then(innerWordsWithQuery); |
| 261 | |
| 262 /** | 261 /** |
| 263 * @param {!Array<string>} words | 262 * @param {!Array<string>} words |
| 264 * @return {!WebInspector.SuggestBox.Suggestions} | 263 * @return {!WebInspector.SuggestBox.Suggestions} |
| 265 */ | 264 */ |
| 266 function innerWordsWithPrefix(words) { | 265 function innerWordsWithQuery(words) { |
| 267 return words.map(item => ({title: item})).concat(historyWords); | 266 return words.map(item => ({title: item})).concat(historyWords); |
| 268 } | 267 } |
| 269 } | 268 } |
| 270 | 269 |
| 271 _editorSetForTest() { | 270 _editorSetForTest() { |
| 272 } | 271 } |
| 273 }; | 272 }; |
| 274 | 273 |
| 275 /** | 274 /** |
| 276 * @unrestricted | 275 * @unrestricted |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 return this._currentHistoryItem(); | 353 return this._currentHistoryItem(); |
| 355 } | 354 } |
| 356 | 355 |
| 357 /** | 356 /** |
| 358 * @return {string|undefined} | 357 * @return {string|undefined} |
| 359 */ | 358 */ |
| 360 _currentHistoryItem() { | 359 _currentHistoryItem() { |
| 361 return this._data[this._data.length - this._historyOffset]; | 360 return this._data[this._data.length - this._historyOffset]; |
| 362 } | 361 } |
| 363 }; | 362 }; |
| OLD | NEW |