Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/console/ConsolePrompt.js

Issue 2769843003: DevTools: split text_utils out of common module (Closed)
Patch Set: rebaseline Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 token = this._editor.tokenAtTextPosition(lineNumber, columnNumber); 244 var token = this._editor.tokenAtTextPosition(lineNumber, columnNumber);
245 if (token && token.type === 'js-string') 245 if (token && token.type === 'js-string')
246 return new Common.TextRange(lineNumber, token.startColumn, lineNumber, col umnNumber); 246 return new TextUtils.TextRange(lineNumber, token.startColumn, lineNumber, columnNumber);
247 247
248 var lineText = this._editor.line(lineNumber); 248 var lineText = this._editor.line(lineNumber);
249 var index; 249 var index;
250 for (index = columnNumber - 1; index >= 0; index--) { 250 for (index = columnNumber - 1; index >= 0; index--) {
251 if (' =:[({;,!+-*/&|^<>.\t\r\n'.indexOf(lineText.charAt(index)) !== -1) 251 if (' =:[({;,!+-*/&|^<>.\t\r\n'.indexOf(lineText.charAt(index)) !== -1)
252 break; 252 break;
253 } 253 }
254 return new Common.TextRange(lineNumber, index + 1, lineNumber, columnNumber) ; 254 return new TextUtils.TextRange(lineNumber, index + 1, lineNumber, columnNumb er);
255 } 255 }
256 256
257 /** 257 /**
258 * @param {!Common.TextRange} queryRange 258 * @param {!TextUtils.TextRange} queryRange
259 * @param {!Common.TextRange} substituteRange 259 * @param {!TextUtils.TextRange} substituteRange
260 * @param {boolean=} force 260 * @param {boolean=} force
261 * @return {!Promise<!UI.SuggestBox.Suggestions>} 261 * @return {!Promise<!UI.SuggestBox.Suggestions>}
262 */ 262 */
263 _wordsWithQuery(queryRange, substituteRange, force) { 263 _wordsWithQuery(queryRange, substituteRange, force) {
264 var query = this._editor.text(queryRange); 264 var query = this._editor.text(queryRange);
265 var before = this._editor.text(new Common.TextRange(0, 0, queryRange.startLi ne, queryRange.startColumn)); 265 var before = this._editor.text(new TextUtils.TextRange(0, 0, queryRange.star tLine, queryRange.startColumn));
266 var historyWords = this._historyCompletions(query, force); 266 var historyWords = this._historyCompletions(query, force);
267 var token = this._editor.tokenAtTextPosition(substituteRange.startLine, subs tituteRange.startColumn); 267 var token = this._editor.tokenAtTextPosition(substituteRange.startLine, subs tituteRange.startColumn);
268 if (token) { 268 if (token) {
269 var excludedTokens = new Set(['js-comment', 'js-string-2', 'js-def']); 269 var excludedTokens = new Set(['js-comment', 'js-string-2', 'js-def']);
270 var trimmedBefore = before.trim(); 270 var trimmedBefore = before.trim();
271 if (!trimmedBefore.endsWith('[') && !trimmedBefore.match(/\.\s*(get|set|de lete)\s*\(\s*$/)) 271 if (!trimmedBefore.endsWith('[') && !trimmedBefore.match(/\.\s*(get|set|de lete)\s*\(\s*$/))
272 excludedTokens.add('js-string'); 272 excludedTokens.add('js-string');
273 if (!trimmedBefore.endsWith('.')) 273 if (!trimmedBefore.endsWith('.'))
274 excludedTokens.add('js-property'); 274 excludedTokens.add('js-property');
275 if (excludedTokens.has(token.type)) 275 if (excludedTokens.has(token.type))
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 return this._currentHistoryItem(); 365 return this._currentHistoryItem();
366 } 366 }
367 367
368 /** 368 /**
369 * @return {string|undefined} 369 * @return {string|undefined}
370 */ 370 */
371 _currentHistoryItem() { 371 _currentHistoryItem() {
372 return this._data[this._data.length - this._historyOffset]; 372 return this._data[this._data.length - this._historyOffset];
373 } 373 }
374 }; 374 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698