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 ffd47423e462767910bb2081411566c8cbaf4850..aa2cba77b643ca9e6b61476e0083c59a5f123881 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,7 @@ WebInspector.TextPrompt = function(completions, stopCharacters) |
this._completionStopCharacters = stopCharacters || " =:[({;,!+-*/&|^<>."; |
this._autocompletionTimeout = WebInspector.TextPrompt.DefaultAutocompletionTimeout; |
this._title = ""; |
+ this._previousText = ""; |
} |
WebInspector.TextPrompt.DefaultAutocompletionTimeout = 250; |
@@ -189,6 +190,7 @@ WebInspector.TextPrompt.prototype = { |
} else { |
this._element.textContent = x; |
} |
+ this._previousText = this.userEnteredText(); |
this.moveCaretToEndOfPrompt(); |
this._element.scrollIntoView(); |
@@ -281,7 +283,22 @@ WebInspector.TextPrompt.prototype = { |
*/ |
_updateAutoComplete: function(force) |
{ |
- this.clearAutoComplete(); |
+ var clearHint = true; |
+ if (this.autoCompleteElement) { |
+ var text = this.userEnteredText(); |
+ if (this._previousText === text.substring(0, text.length - 1)) { |
+ this._hintPrefix += this.autoCompleteElement.textContent.charAt(0); |
+ this.autoCompleteElement.textContent = this.autoCompleteElement.textContent.substring(1); |
+ clearHint = false; |
+ } else if (this._previousText.substring(0, this._previousText.length - 1) === text) { |
lushnikov
2016/09/07 22:11:01
let's use .startsWith?
einbinder
2016/10/18 00:57:33
Done.
|
+ this.autoCompleteElement.textContent = this._hintPrefix.charAt(this._hintPrefix.length - 1) + this.autoCompleteElement.textContent; |
+ this._hintPrefix = this._hintPrefix.substring(0, this._hintPrefix.length - 1); |
+ clearHint = false; |
+ } |
+ } |
+ if (clearHint) |
+ this.clearAutoComplete(); |
+ delete this._waitingForCompletions; |
lushnikov
2016/09/07 22:11:01
why would you need to delete this?
The _waitingFo
einbinder
2016/10/18 00:57:33
Done.
|
this.autoCompleteSoon(force); |
}, |
@@ -355,6 +372,7 @@ WebInspector.TextPrompt.prototype = { |
{ |
if (this._needUpdateAutocomplete) |
this._updateAutoComplete(); |
+ this._previousText = this.userEnteredText(); |
}, |
/** |
@@ -376,10 +394,8 @@ WebInspector.TextPrompt.prototype = { |
if (this.isSuggestBoxVisible()) |
this._suggestBox.hide(); |
- if (this._completeTimeout) { |
- clearTimeout(this._completeTimeout); |
- delete this._completeTimeout; |
- } |
+ this._clearAutocompleteTimeout(); |
+ |
delete this._waitingForCompletions; |
if (!this.autoCompleteElement) |
@@ -391,6 +407,14 @@ WebInspector.TextPrompt.prototype = { |
delete this._userEnteredText; |
}, |
+ _clearAutocompleteTimeout: function() |
+ { |
+ if (this._completeTimeout) { |
+ clearTimeout(this._completeTimeout); |
+ delete this._completeTimeout; |
+ } |
+ }, |
+ |
/** |
* @param {boolean=} force |
*/ |
@@ -407,7 +431,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) |
@@ -422,7 +446,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) { |
@@ -560,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._hintPrefix = completionText.substring(0, wordPrefixLength); |
prefixTextNode.parentNode.insertBefore(this.autoCompleteElement, prefixTextNode.nextSibling); |