| 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 Console.ConsolePrompt = class extends UI.Widget { | 7 Console.ConsolePrompt = class extends UI.Widget { |
| 8 constructor() { | 8 constructor() { |
| 9 super(); | 9 super(); |
| 10 this._addCompletionsFromHistory = true; | 10 this._addCompletionsFromHistory = true; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 else | 234 else |
| 235 this.element.focus(); | 235 this.element.focus(); |
| 236 } | 236 } |
| 237 | 237 |
| 238 /** | 238 /** |
| 239 * @param {number} lineNumber | 239 * @param {number} lineNumber |
| 240 * @param {number} columnNumber | 240 * @param {number} columnNumber |
| 241 * @return {?Common.TextRange} | 241 * @return {?Common.TextRange} |
| 242 */ | 242 */ |
| 243 _substituteRange(lineNumber, columnNumber) { | 243 _substituteRange(lineNumber, columnNumber) { |
| 244 var token = this._editor.tokenAtTextPosition(lineNumber, columnNumber); |
| 245 if (token && token.type === 'js-string') |
| 246 return new Common.TextRange(lineNumber, token.startColumn, lineNumber, col
umnNumber); |
| 247 |
| 244 var lineText = this._editor.line(lineNumber); | 248 var lineText = this._editor.line(lineNumber); |
| 245 var index; | 249 var index; |
| 246 for (index = columnNumber - 1; index >= 0; index--) { | 250 for (index = columnNumber - 1; index >= 0; index--) { |
| 247 if (' =:[({;,!+-*/&|^<>.\t\r\n'.indexOf(lineText.charAt(index)) !== -1) | 251 if (' =:[({;,!+-*/&|^<>.\t\r\n'.indexOf(lineText.charAt(index)) !== -1) |
| 248 break; | 252 break; |
| 249 } | 253 } |
| 250 return new Common.TextRange(lineNumber, index + 1, lineNumber, columnNumber)
; | 254 return new Common.TextRange(lineNumber, index + 1, lineNumber, columnNumber)
; |
| 251 } | 255 } |
| 252 | 256 |
| 253 /** | 257 /** |
| 254 * @param {!Common.TextRange} queryRange | 258 * @param {!Common.TextRange} queryRange |
| 255 * @param {!Common.TextRange} substituteRange | 259 * @param {!Common.TextRange} substituteRange |
| 256 * @param {boolean=} force | 260 * @param {boolean=} force |
| 257 * @param {string=} currentTokenType | |
| 258 * @return {!Promise<!UI.SuggestBox.Suggestions>} | 261 * @return {!Promise<!UI.SuggestBox.Suggestions>} |
| 259 */ | 262 */ |
| 260 _wordsWithQuery(queryRange, substituteRange, force, currentTokenType) { | 263 _wordsWithQuery(queryRange, substituteRange, force) { |
| 261 var query = this._editor.text(queryRange); | 264 var query = this._editor.text(queryRange); |
| 262 var before = this._editor.text(new Common.TextRange(0, 0, queryRange.startLi
ne, queryRange.startColumn)); | 265 var before = this._editor.text(new Common.TextRange(0, 0, queryRange.startLi
ne, queryRange.startColumn)); |
| 263 var historyWords = this._historyCompletions(query, force); | 266 var historyWords = this._historyCompletions(query, force); |
| 264 | 267 var token = this._editor.tokenAtTextPosition(substituteRange.startLine, subs
tituteRange.startColumn); |
| 265 var excludedTokens = new Set(['js-comment', 'js-string-2', 'js-def']); | 268 if (token) { |
| 266 var trimmedBefore = before.trim(); | 269 var excludedTokens = new Set(['js-comment', 'js-string-2', 'js-def']); |
| 267 if (!trimmedBefore.endsWith('[') && !trimmedBefore.match(/\.\s*(get|set|dele
te)\s*\(\s*$/)) | 270 var trimmedBefore = before.trim(); |
| 268 excludedTokens.add('js-string'); | 271 if (!trimmedBefore.endsWith('[') && !trimmedBefore.match(/\.\s*(get|set|de
lete)\s*\(\s*$/)) |
| 269 if (!trimmedBefore.endsWith('.')) | 272 excludedTokens.add('js-string'); |
| 270 excludedTokens.add('js-property'); | 273 if (!trimmedBefore.endsWith('.')) |
| 271 if (excludedTokens.has(currentTokenType)) | 274 excludedTokens.add('js-property'); |
| 272 return Promise.resolve(historyWords); | 275 if (excludedTokens.has(token.type)) |
| 273 | 276 return Promise.resolve(historyWords); |
| 277 } |
| 274 return ObjectUI.JavaScriptAutocomplete.completionsForTextInCurrentContext(be
fore, query, force) | 278 return ObjectUI.JavaScriptAutocomplete.completionsForTextInCurrentContext(be
fore, query, force) |
| 275 .then(words => words.concat(historyWords)); | 279 .then(words => words.concat(historyWords)); |
| 276 } | 280 } |
| 277 | 281 |
| 278 _editorSetForTest() { | 282 _editorSetForTest() { |
| 279 } | 283 } |
| 280 }; | 284 }; |
| 281 | 285 |
| 282 /** | 286 /** |
| 283 * @unrestricted | 287 * @unrestricted |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 return this._currentHistoryItem(); | 365 return this._currentHistoryItem(); |
| 362 } | 366 } |
| 363 | 367 |
| 364 /** | 368 /** |
| 365 * @return {string|undefined} | 369 * @return {string|undefined} |
| 366 */ | 370 */ |
| 367 _currentHistoryItem() { | 371 _currentHistoryItem() { |
| 368 return this._data[this._data.length - this._historyOffset]; | 372 return this._data[this._data.length - this._historyOffset]; |
| 369 } | 373 } |
| 370 }; | 374 }; |
| OLD | NEW |