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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/text_editor/TextEditorAutocompleteController.js

Issue 2760583002: DevTools: Don't give up autocomplete after a fancy character in a string (Closed)
Patch Set: merge 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 (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 * @implements {UI.SuggestBoxDelegate} 5 * @implements {UI.SuggestBoxDelegate}
6 * @unrestricted 6 * @unrestricted
7 */ 7 */
8 TextEditor.TextEditorAutocompleteController = class { 8 TextEditor.TextEditorAutocompleteController = class {
9 /** 9 /**
10 * @param {!TextEditor.CodeMirrorTextEditor} textEditor 10 * @param {!TextEditor.CodeMirrorTextEditor} textEditor
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 this._config.substituteRangeCallback ? this._config.substituteRangeCallb ack(lineNumber, columnNumber) : null; 103 this._config.substituteRangeCallback ? this._config.substituteRangeCallb ack(lineNumber, columnNumber) : null;
104 if (!range && this._config.isWordChar) 104 if (!range && this._config.isWordChar)
105 range = this._textEditor.wordRangeForCursorPosition(lineNumber, columnNumb er, this._config.isWordChar); 105 range = this._textEditor.wordRangeForCursorPosition(lineNumber, columnNumb er, this._config.isWordChar);
106 return range; 106 return range;
107 } 107 }
108 108
109 /** 109 /**
110 * @param {!Common.TextRange} queryRange 110 * @param {!Common.TextRange} queryRange
111 * @param {!Common.TextRange} substituteRange 111 * @param {!Common.TextRange} substituteRange
112 * @param {boolean=} force 112 * @param {boolean=} force
113 * @param {string=} tokenType
114 * @return {!Promise.<!UI.SuggestBox.Suggestions>} 113 * @return {!Promise.<!UI.SuggestBox.Suggestions>}
115 */ 114 */
116 _wordsWithQuery(queryRange, substituteRange, force, tokenType) { 115 _wordsWithQuery(queryRange, substituteRange, force) {
117 var external = this._config.suggestionsCallback ? 116 var external =
118 this._config.suggestionsCallback(queryRange, substituteRange, force, tok enType) : 117 this._config.suggestionsCallback ? this._config.suggestionsCallback(quer yRange, substituteRange, force) : null;
119 null;
120 if (external) 118 if (external)
121 return external; 119 return external;
122 120
123 if (!this._dictionary || (!force && queryRange.isEmpty())) 121 if (!this._dictionary || (!force && queryRange.isEmpty()))
124 return Promise.resolve([]); 122 return Promise.resolve([]);
125 123
126 var completions = this._dictionary.wordsWithPrefix(this._textEditor.text(que ryRange)); 124 var completions = this._dictionary.wordsWithPrefix(this._textEditor.text(que ryRange));
127 var substituteWord = this._textEditor.text(substituteRange); 125 var substituteWord = this._textEditor.text(substituteRange);
128 if (this._dictionary.wordCount(substituteWord) === 1) 126 if (this._dictionary.wordCount(substituteWord) === 1)
129 completions = completions.filter(word => word !== substituteWord); 127 completions = completions.filter(word => word !== substituteWord);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 this.clearAutocomplete(); 226 this.clearAutocomplete();
229 return; 227 return;
230 } 228 }
231 229
232 var queryRange = substituteRange.clone(); 230 var queryRange = substituteRange.clone();
233 queryRange.endColumn = cursor.ch; 231 queryRange.endColumn = cursor.ch;
234 var query = this._textEditor.text(queryRange); 232 var query = this._textEditor.text(queryRange);
235 var hadSuggestBox = false; 233 var hadSuggestBox = false;
236 if (this._suggestBox) 234 if (this._suggestBox)
237 hadSuggestBox = true; 235 hadSuggestBox = true;
238 var token = this._textEditor.tokenAtTextPosition(substituteRange.startLine, substituteRange.startColumn); 236 this._wordsWithQuery(queryRange, substituteRange, force).then(wordsAcquired. bind(this));
239 var tokenType = (token && token.type) || '';
240 this._wordsWithQuery(queryRange, substituteRange, force, tokenType).then(wor dsAcquired.bind(this));
241 237
242 /** 238 /**
243 * @param {!UI.SuggestBox.Suggestions} wordsWithQuery 239 * @param {!UI.SuggestBox.Suggestions} wordsWithQuery
244 * @this {TextEditor.TextEditorAutocompleteController} 240 * @this {TextEditor.TextEditorAutocompleteController}
245 */ 241 */
246 function wordsAcquired(wordsWithQuery) { 242 function wordsAcquired(wordsWithQuery) {
247 if (!wordsWithQuery.length || (wordsWithQuery.length === 1 && query === wo rdsWithQuery[0].text) || 243 if (!wordsWithQuery.length || (wordsWithQuery.length === 1 && query === wo rdsWithQuery[0].text) ||
248 (!this._suggestBox && hadSuggestBox)) { 244 (!this._suggestBox && hadSuggestBox)) {
249 this.clearAutocomplete(); 245 this.clearAutocomplete();
250 this._onSuggestionsShownForTest([]); 246 this._onSuggestionsShownForTest([]);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 420
425 _updateAnchorBox() { 421 _updateAnchorBox() {
426 var line = this._queryRange.startLine; 422 var line = this._queryRange.startLine;
427 var column = this._queryRange.startColumn; 423 var column = this._queryRange.startColumn;
428 var metrics = this._textEditor.cursorPositionToCoordinates(line, column); 424 var metrics = this._textEditor.cursorPositionToCoordinates(line, column);
429 this._anchorBox = metrics ? new AnchorBox(metrics.x, metrics.y, 0, metrics.h eight) : null; 425 this._anchorBox = metrics ? new AnchorBox(metrics.x, metrics.y, 0, metrics.h eight) : null;
430 } 426 }
431 }; 427 };
432 428
433 TextEditor.TextEditorAutocompleteController.HintBookmark = Symbol('hint'); 429 TextEditor.TextEditorAutocompleteController.HintBookmark = Symbol('hint');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698