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

Unified Diff: third_party/WebKit/Source/devtools/front_end/ui/TextPrompt.js

Issue 2285993002: DevTools: Fix flickering hint when typing in TextPrompt (Closed)
Patch Set: Refactor Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 839f4b9bc35705059205e754168429f1a2463eca..5157a41f19c4ba07c685812344bdff09b9b9de2c 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();
@@ -287,7 +289,23 @@ WebInspector.TextPrompt.prototype = {
*/
_updateAutoComplete: function(force)
{
- this.clearAutoComplete();
+ var clearHint = true;
+ if (this._autocompleteElement) {
lushnikov 2016/08/31 15:11:16 what is this._autocompleteElement? AFAIU it is nev
einbinder 2016/08/31 21:19:01 Was a typo in a refactor. Fixed it.
+ 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) {
+ 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(false);
+ delete this._waitingForCompletions;
this.autoCompleteSoon(force);
},
@@ -361,6 +379,7 @@ WebInspector.TextPrompt.prototype = {
{
if (this._needUpdateAutocomplete)
this._updateAutoComplete();
+ this._previousText = this.userEnteredText();
},
/**
@@ -382,10 +401,9 @@ WebInspector.TextPrompt.prototype = {
*/
clearAutoComplete: function(includeTimeout)
{
- if (includeTimeout && this._completeTimeout) {
- clearTimeout(this._completeTimeout);
- delete this._completeTimeout;
- }
+ if (includeTimeout)
+ this._clearAutocompleteTimeout();
+
delete this._waitingForCompletions;
if (!this.autoCompleteElement)
@@ -397,6 +415,14 @@ WebInspector.TextPrompt.prototype = {
delete this._userEnteredText;
},
+ _clearAutocompleteTimeout: function()
+ {
+ if (this._completeTimeout) {
+ clearTimeout(this._completeTimeout);
+ delete this._completeTimeout;
+ }
+ },
+
/**
* @param {boolean=} force
*/
@@ -413,7 +439,7 @@ WebInspector.TextPrompt.prototype = {
*/
complete: function(force, reverse)
{
- this.clearAutoComplete(true);
+ this._clearAutocompleteTimeout();
var selection = this._element.getComponentSelection();
var selectionRange = selection && selection.rangeCount ? selection.getRangeAt(0) : null;
if (!selectionRange)
@@ -428,11 +454,11 @@ 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) {
- this.hideSuggestBox();
+ this._removeSuggestionAids();
return;
}
@@ -526,7 +552,7 @@ WebInspector.TextPrompt.prototype = {
}
if (!this._waitingForCompletions || !annotatedCompletions.length) {
- this.hideSuggestBox();
+ this._removeSuggestionAids();
return;
}
@@ -566,8 +592,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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698