| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * @return {boolean} | 59 * @return {boolean} |
| 60 */ | 60 */ |
| 61 _isCaretAtEndOfPrompt() { | 61 _isCaretAtEndOfPrompt() { |
| 62 return !!this._editor && this._editor.selection().collapseToEnd().equal(this
._editor.fullRange().collapseToEnd()); | 62 return !!this._editor && this._editor.selection().collapseToEnd().equal(this
._editor.fullRange().collapseToEnd()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 moveCaretToEndOfPrompt() { | 65 moveCaretToEndOfPrompt() { |
| 66 if (this._editor) | 66 if (this._editor) |
| 67 this._editor.setSelection(Common.TextRange.createFromLocation(Infinity, In
finity)); | 67 this._editor.setSelection(TextUtils.TextRange.createFromLocation(Infinity,
Infinity)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * @param {string} text | 71 * @param {string} text |
| 72 */ | 72 */ |
| 73 setText(text) { | 73 setText(text) { |
| 74 if (this._editor) | 74 if (this._editor) |
| 75 this._editor.setText(text); | 75 this._editor.setText(text); |
| 76 else | 76 else |
| 77 this._initialText = text; | 77 this._initialText = text; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 this._enterKeyPressed(keyboardEvent); | 127 this._enterKeyPressed(keyboardEvent); |
| 128 break; | 128 break; |
| 129 } | 129 } |
| 130 | 130 |
| 131 if (newText === undefined) | 131 if (newText === undefined) |
| 132 return; | 132 return; |
| 133 keyboardEvent.consume(true); | 133 keyboardEvent.consume(true); |
| 134 this.setText(newText); | 134 this.setText(newText); |
| 135 | 135 |
| 136 if (isPrevious) | 136 if (isPrevious) |
| 137 this._editor.setSelection(Common.TextRange.createFromLocation(0, Infinity)
); | 137 this._editor.setSelection(TextUtils.TextRange.createFromLocation(0, Infini
ty)); |
| 138 else | 138 else |
| 139 this.moveCaretToEndOfPrompt(); | 139 this.moveCaretToEndOfPrompt(); |
| 140 this.setMinimumSize(0, this._editor.widget().element.offsetHeight); | 140 this.setMinimumSize(0, this._editor.widget().element.offsetHeight); |
| 141 } | 141 } |
| 142 | 142 |
| 143 /** | 143 /** |
| 144 * @param {!KeyboardEvent} event | 144 * @param {!KeyboardEvent} event |
| 145 */ | 145 */ |
| 146 _enterKeyPressed(event) { | 146 _enterKeyPressed(event) { |
| 147 if (event.altKey || event.ctrlKey || event.shiftKey) | 147 if (event.altKey || event.ctrlKey || event.shiftKey) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 focus() { | 231 focus() { |
| 232 if (this._editor) | 232 if (this._editor) |
| 233 this._editor.widget().focus(); | 233 this._editor.widget().focus(); |
| 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 {?TextUtils.TextRange} |
| 242 */ | 242 */ |
| 243 _substituteRange(lineNumber, columnNumber) { | 243 _substituteRange(lineNumber, columnNumber) { |
| 244 var lineText = this._editor.line(lineNumber); | 244 var lineText = this._editor.line(lineNumber); |
| 245 var index; | 245 var index; |
| 246 for (index = columnNumber - 1; index >= 0; index--) { | 246 for (index = columnNumber - 1; index >= 0; index--) { |
| 247 if (' =:[({;,!+-*/&|^<>.\t\r\n'.indexOf(lineText.charAt(index)) !== -1) | 247 if (' =:[({;,!+-*/&|^<>.\t\r\n'.indexOf(lineText.charAt(index)) !== -1) |
| 248 break; | 248 break; |
| 249 } | 249 } |
| 250 return new Common.TextRange(lineNumber, index + 1, lineNumber, columnNumber)
; | 250 return new TextUtils.TextRange(lineNumber, index + 1, lineNumber, columnNumb
er); |
| 251 } | 251 } |
| 252 | 252 |
| 253 /** | 253 /** |
| 254 * @param {!Common.TextRange} queryRange | 254 * @param {!TextUtils.TextRange} queryRange |
| 255 * @param {!Common.TextRange} substituteRange | 255 * @param {!TextUtils.TextRange} substituteRange |
| 256 * @param {boolean=} force | 256 * @param {boolean=} force |
| 257 * @param {string=} currentTokenType | 257 * @param {string=} currentTokenType |
| 258 * @return {!Promise<!UI.SuggestBox.Suggestions>} | 258 * @return {!Promise<!UI.SuggestBox.Suggestions>} |
| 259 */ | 259 */ |
| 260 _wordsWithQuery(queryRange, substituteRange, force, currentTokenType) { | 260 _wordsWithQuery(queryRange, substituteRange, force, currentTokenType) { |
| 261 var query = this._editor.text(queryRange); | 261 var query = this._editor.text(queryRange); |
| 262 var before = this._editor.text(new Common.TextRange(0, 0, queryRange.startLi
ne, queryRange.startColumn)); | 262 var before = this._editor.text(new TextUtils.TextRange(0, 0, queryRange.star
tLine, queryRange.startColumn)); |
| 263 var historyWords = this._historyCompletions(query, force); | 263 var historyWords = this._historyCompletions(query, force); |
| 264 | 264 |
| 265 var excludedTokens = new Set(['js-comment', 'js-string-2', 'js-def']); | 265 var excludedTokens = new Set(['js-comment', 'js-string-2', 'js-def']); |
| 266 var trimmedBefore = before.trim(); | 266 var trimmedBefore = before.trim(); |
| 267 if (!trimmedBefore.endsWith('[') && !trimmedBefore.match(/\.\s*(get|set|dele
te)\s*\(\s*$/)) | 267 if (!trimmedBefore.endsWith('[') && !trimmedBefore.match(/\.\s*(get|set|dele
te)\s*\(\s*$/)) |
| 268 excludedTokens.add('js-string'); | 268 excludedTokens.add('js-string'); |
| 269 if (!trimmedBefore.endsWith('.')) | 269 if (!trimmedBefore.endsWith('.')) |
| 270 excludedTokens.add('js-property'); | 270 excludedTokens.add('js-property'); |
| 271 if (excludedTokens.has(currentTokenType)) | 271 if (excludedTokens.has(currentTokenType)) |
| 272 return Promise.resolve(historyWords); | 272 return Promise.resolve(historyWords); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 return this._currentHistoryItem(); | 361 return this._currentHistoryItem(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 /** | 364 /** |
| 365 * @return {string|undefined} | 365 * @return {string|undefined} |
| 366 */ | 366 */ |
| 367 _currentHistoryItem() { | 367 _currentHistoryItem() { |
| 368 return this._data[this._data.length - this._historyOffset]; | 368 return this._data[this._data.length - this._historyOffset]; |
| 369 } | 369 } |
| 370 }; | 370 }; |
| OLD | NEW |