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

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: currentHintText Created 4 years, 2 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 | « third_party/WebKit/LayoutTests/http/tests/inspector-unit/text-prompt-hint-expected.txt ('k') | 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 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);
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/inspector-unit/text-prompt-hint-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698