Title: [100981] trunk/Source/WebCore
Revision
100981
Author
apav...@chromium.org
Date
2011-11-22 01:18:46 -0800 (Tue, 22 Nov 2011)

Log Message

Web Inspector: Design of the autocomplete suggest
https://bugs.webkit.org/show_bug.cgi?id=72798

Reviewed by Pavel Feldman.

Implemented a combination of grayed text for the first/only completion and hid
the suggest box for a single suggestion (the grayed text is displayed instead.)
Drive-by fix for the "trailing spaces in the prompt" issue
(got regressed when the suggest box was introduced for the first time.)

* inspector/front-end/ConsoleView.js:
(WebInspector.ConsoleView): Fix the "trailing spaces" issue
* inspector/front-end/TextPrompt.js:
(WebInspector.TextPrompt):
(WebInspector.TextPrompt.prototype.renderAsBlock): Fix the "trailing spaces" issue
(WebInspector.TextPrompt.prototype._attachInternal):
(WebInspector.TextPrompt.prototype.acceptAutoComplete):
(WebInspector.TextPrompt.prototype._completionsReady):
(WebInspector.TextPrompt.prototype.applySuggestion):
(WebInspector.TextPrompt.prototype.acceptSuggestion):
(WebInspector.TextPrompt.SuggestBox.prototype._completionsReady):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (100980 => 100981)


--- trunk/Source/WebCore/ChangeLog	2011-11-22 08:50:59 UTC (rev 100980)
+++ trunk/Source/WebCore/ChangeLog	2011-11-22 09:18:46 UTC (rev 100981)
@@ -1,3 +1,27 @@
+2011-11-22  Alexander Pavlov  <apav...@chromium.org>
+
+        Web Inspector: Design of the autocomplete suggest
+        https://bugs.webkit.org/show_bug.cgi?id=72798
+
+        Reviewed by Pavel Feldman.
+
+        Implemented a combination of grayed text for the first/only completion and hid
+        the suggest box for a single suggestion (the grayed text is displayed instead.)
+        Drive-by fix for the "trailing spaces in the prompt" issue
+        (got regressed when the suggest box was introduced for the first time.)
+
+        * inspector/front-end/ConsoleView.js:
+        (WebInspector.ConsoleView): Fix the "trailing spaces" issue
+        * inspector/front-end/TextPrompt.js:
+        (WebInspector.TextPrompt):
+        (WebInspector.TextPrompt.prototype.renderAsBlock): Fix the "trailing spaces" issue
+        (WebInspector.TextPrompt.prototype._attachInternal):
+        (WebInspector.TextPrompt.prototype.acceptAutoComplete):
+        (WebInspector.TextPrompt.prototype._completionsReady):
+        (WebInspector.TextPrompt.prototype.applySuggestion):
+        (WebInspector.TextPrompt.prototype.acceptSuggestion):
+        (WebInspector.TextPrompt.SuggestBox.prototype._completionsReady):
+
 2011-11-21  David Barr  <davidb...@chromium.org>
 
         REGRESSION(r98542): Chromium: CSS text is rendered on page

Modified: trunk/Source/WebCore/inspector/front-end/ConsoleView.js (100980 => 100981)


--- trunk/Source/WebCore/inspector/front-end/ConsoleView.js	2011-11-22 08:50:59 UTC (rev 100980)
+++ trunk/Source/WebCore/inspector/front-end/ConsoleView.js	2011-11-22 09:18:46 UTC (rev 100981)
@@ -113,6 +113,7 @@
 
     this.prompt = new WebInspector.TextPromptWithHistory(this.completions.bind(this), ExpressionStopCharacters + ".");
     this.prompt.setSuggestBoxEnabled("generic-suggest");
+    this.prompt.renderAsBlock();
     this.prompt.attach(this.promptElement);
     this.prompt.proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this), false);
     this.prompt.setHistoryData(WebInspector.settings.consoleHistory.get());

Modified: trunk/Source/WebCore/inspector/front-end/TextPrompt.js (100980 => 100981)


--- trunk/Source/WebCore/inspector/front-end/TextPrompt.js	2011-11-22 08:50:59 UTC (rev 100980)
+++ trunk/Source/WebCore/inspector/front-end/TextPrompt.js	2011-11-22 09:18:46 UTC (rev 100981)
@@ -39,6 +39,7 @@
      * @type {Element|undefined}
      */
     this._proxyElement;
+    this._proxyElementDisplay = "inline-block";
     this._loadCompletions = completions;
     this._completionStopCharacters = stopCharacters;
     this._suggestForceable = true;
@@ -65,6 +66,11 @@
         this._suggestBoxClassName = className;
     },
 
+    renderAsBlock: function()
+    {
+        this._proxyElementDisplay = "block";
+    },
+
     /**
      * Clients should never attach any event listeners to the |element|. Instead,
      * they should use the result of this method to attach listeners for bubbling events.
@@ -101,7 +107,7 @@
         this._boundOnKeyDown = this.onKeyDown.bind(this);
         this._boundSelectStart = this._selectStart.bind(this);
         this._proxyElement = element.ownerDocument.createElement("span");
-        this._proxyElement.style.display = "inline-block";
+        this._proxyElement.style.display = this._proxyElementDisplay;
         element.parentElement.insertBefore(this.proxyElement, element);
         this.proxyElement.appendChild(element);
         this._element.addStyleClass("text-prompt");
@@ -269,26 +275,9 @@
 
     acceptAutoComplete: function()
     {
-        if (!this.autoCompleteElement || !this.autoCompleteElement.parentNode)
-            return false;
-
         if (this.isSuggestBoxVisible())
-            this._suggestBox.acceptSuggestion();
-
-        var text = this.autoCompleteElement.textContent;
-        var textNode = document.createTextNode(text);
-        this.autoCompleteElement.parentNode.replaceChild(textNode, this.autoCompleteElement);
-        delete this.autoCompleteElement;
-
-        var finalSelectionRange = document.createRange();
-        finalSelectionRange.setStart(textNode, text.length);
-        finalSelectionRange.setEnd(textNode, text.length);
-
-        var selection = window.getSelection();
-        selection.removeAllRanges();
-        selection.addRange(finalSelectionRange);
-
-        return true;
+            return this._suggestBox.acceptSuggestion();
+        return this.acceptSuggestion();
     },
 
     /**
@@ -413,10 +402,8 @@
         this._userEnteredRange = fullWordRange;
         this._userEnteredText = fullWordRange.toString();
 
-        if (this._suggestBox) {
+        if (this._suggestBox)
             this._suggestBox.updateSuggestions(this._boxForAnchorAtStart(selection, fullWordRange), completions);
-            return; // Do nothing, the suggest box is driving us.
-        }
 
         var wordPrefixLength = originalWordPrefixRange.toString().length;
 
@@ -502,6 +489,10 @@
         var finalSelectionRange = document.createRange();
         var completionTextNode = document.createTextNode(completionText);
         this._userEnteredRange.insertNode(completionTextNode);
+        if (this.autoCompleteElement && this.autoCompleteElement.parentNode) {
+            this.autoCompleteElement.parentNode.removeChild(this.autoCompleteElement);
+            delete this.autoCompleteElement;
+        }
 
         if (isIntermediateSuggestion)
             finalSelectionRange.setStart(completionTextNode, wordPrefixLength);
@@ -519,10 +510,30 @@
 
     acceptSuggestion: function()
     {
-        this.acceptAutoComplete();
+        if (this._isAcceptingSuggestion)
+            return false;
+
+        if (!this.autoCompleteElement || !this.autoCompleteElement.parentNode)
+            return false;
+
+        var text = this.autoCompleteElement.textContent;
+        var textNode = document.createTextNode(text);
+        this.autoCompleteElement.parentNode.replaceChild(textNode, this.autoCompleteElement);
+        delete this.autoCompleteElement;
+
+        var finalSelectionRange = document.createRange();
+        finalSelectionRange.setStart(textNode, text.length);
+        finalSelectionRange.setEnd(textNode, text.length);
+
+        var selection = window.getSelection();
+        selection.removeAllRanges();
+        selection.addRange(finalSelectionRange);
+
         if (this._suggestBox)
             this._suggestBox.hide();
         this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemAccepted);
+
+        return true;
     },
 
     isSuggestBoxVisible: function()
@@ -1088,7 +1099,7 @@
 
         this._updateItems(completions);
         this._updateBoxPosition(anchorBox);
-        if (this.contentElement.children.length && (this.contentElement.children.length > 1 || this.contentElement.children[0].textContent.length !== this._textPrompt._userEnteredText.length)) {
+        if (this.contentElement.children.length && this.contentElement.children.length > 1) {
             // Will not be shown if a sole suggestion is equal to the user input.
             this._element.addStyleClass("visible");
         } else
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to