Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/ui/TextPrompt.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/ui/TextPrompt.js b/third_party/WebKit/Source/devtools/front_end/ui/TextPrompt.js |
| index 8ec159fc70c3c1f62ed4caa0c863fc533be1e904..401ec4125d1289276368b7a94fad47e4a7e45609 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/ui/TextPrompt.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/ui/TextPrompt.js |
| @@ -45,6 +45,8 @@ WebInspector.TextPrompt = function(completions, stopCharacters) |
| this._completionStopCharacters = stopCharacters || " =:[({;,!+-*/&|^<>."; |
| this._autocompletionTimeout = WebInspector.TextPrompt.DefaultAutocompletionTimeout; |
| this._title = ""; |
| + this._previousText = ""; |
| + this._currentHintText = ""; |
| this._completionRequestId = 0; |
| } |
| @@ -190,6 +192,7 @@ WebInspector.TextPrompt.prototype = { |
| } else { |
| this._element.textContent = x; |
| } |
| + this._previousText = this.userEnteredText(); |
| this.moveCaretToEndOfPrompt(); |
| this._element.scrollIntoView(); |
| @@ -282,7 +285,16 @@ WebInspector.TextPrompt.prototype = { |
| */ |
| _updateAutoComplete: function(force) |
|
lushnikov
2016/10/19 23:36:47
let's get rid of this method - it's confusing
einbinder
2016/10/20 01:21:44
Done.
|
| { |
| - this._clearAutocompleteElement(); |
| + var clearHint = true; |
| + if (this._autocompleteElement) { |
|
lushnikov
2016/10/19 23:36:47
var hasCommonPrefix = text.startsWith(this._previo
einbinder
2016/10/20 01:21:44
Done.
|
| + var text = this.userEnteredText(); |
| + if (text.startsWith(this._previousText) || this._previousText.startsWith(text)) { |
| + this._autocompleteElement.textContent = this._currentHintText.substring(text.length); |
| + clearHint = false; |
| + } |
| + } |
| + if (clearHint) |
| + this._clearAutocompleteElement(); |
| this.autoCompleteSoon(force); |
| }, |
| @@ -356,6 +368,7 @@ WebInspector.TextPrompt.prototype = { |
| { |
| if (this._needUpdateAutocomplete) |
| this._updateAutoComplete(); |
| + this._previousText = this.userEnteredText(); |
| }, |
| /** |
| @@ -381,10 +394,8 @@ WebInspector.TextPrompt.prototype = { |
| _clearAutocompleteElement: function() |
| { |
| - if (this._completeTimeout) { |
| - clearTimeout(this._completeTimeout); |
| - delete this._completeTimeout; |
| - } |
| + this._clearAutocompleteTimeout(); |
| + this._completionRequestId++; |
|
lushnikov
2016/10/19 23:36:47
let's move this into _clearAutocompleteTimeout
einbinder
2016/10/20 01:21:44
Done.
|
| if (!this._autocompleteElement) |
| return; |
| @@ -395,6 +406,14 @@ WebInspector.TextPrompt.prototype = { |
| delete this._userEnteredText; |
| }, |
| + _clearAutocompleteTimeout: function() |
| + { |
| + if (this._completeTimeout) { |
| + clearTimeout(this._completeTimeout); |
| + delete this._completeTimeout; |
| + } |
| + }, |
| + |
| /** |
| * @param {boolean=} force |
| */ |
| @@ -411,7 +430,7 @@ WebInspector.TextPrompt.prototype = { |
| */ |
| complete: function(force, reverse) |
| { |
| - this.clearAutocomplete(); |
| + this._clearAutocompleteTimeout(); |
| var selection = this._element.getComponentSelection(); |
| var selectionRange = selection && selection.rangeCount ? selection.getRangeAt(0) : null; |
| if (!selectionRange) |
| @@ -426,7 +445,7 @@ WebInspector.TextPrompt.prototype = { |
| else if (!force) { |
| // BUG72018: Do not show suggest box if caret is followed by a non-stop character. |
| var wordSuffixRange = selectionRange.startContainer.rangeOfWord(selectionRange.endOffset, this._completionStopCharacters, this._element, "forward"); |
| - if (wordSuffixRange.toString().length) |
| + if (wordSuffixRange.toString().length + this.userEnteredText().length - this.text().length) |
| shouldExit = true; |
| } |
| if (shouldExit) { |
| @@ -565,8 +584,10 @@ WebInspector.TextPrompt.prototype = { |
| var prefixTextNode = createTextNode(prefixText); |
| fullWordRange.insertNode(prefixTextNode); |
| - this._autocompleteElement = createElementWithClass("span", "auto-complete-text"); |
| + if (!this._autocompleteElement) |
| + this._autocompleteElement = createElementWithClass("span", "auto-complete-text"); |
| this._autocompleteElement.textContent = suffixText; |
| + this._currentHintText = completionText; |
| prefixTextNode.parentNode.insertBefore(this._autocompleteElement, prefixTextNode.nextSibling); |