Title: [186217] trunk/Source/WebInspectorUI
Revision
186217
Author
drou...@apple.com
Date
2015-07-01 21:30:53 -0700 (Wed, 01 Jul 2015)

Log Message

Web Inspector: When autocompleting, pressing tab twice shouldn't insert a tab character
https://bugs.webkit.org/show_bug.cgi?id=145885

Reviewed by Timothy Hatcher.

* UserInterface/Controllers/CodeMirrorCompletionController.js:
(WebInspector.CodeMirrorCompletionController):
(WebInspector.CodeMirrorCompletionController.prototype.updateCompletions): Resolves the promise as having completions.
(WebInspector.CodeMirrorCompletionController.prototype.hideCompletions): Resolves the promise as not having completions.
(WebInspector.CodeMirrorCompletionController.prototype.completeAtCurrentPositionIfNeeded): Returns a WrappedPromise that allows
callers of this function to determine if the autocomplete had any values or was instead not shown.
(WebInspector.CodeMirrorCompletionController.prototype._resolveUpdatePromise):
* UserInterface/Main.html: Added WrappedPromise class.
* UserInterface/Models/WrappedPromise.js: Added WrappedPromise object to expose resolve and reject functions.
* UserInterface/Views/ConsolePrompt.js:
(WebInspector.ConsolePrompt.prototype._handleTabKey): Attempts to find completions for current text.  If there are none, beep.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (186216 => 186217)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-07-02 04:01:03 UTC (rev 186216)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-07-02 04:30:53 UTC (rev 186217)
@@ -1,5 +1,24 @@
 2015-07-01  Devin Rousso  <drou...@apple.com>
 
+        Web Inspector: When autocompleting, pressing tab twice shouldn't insert a tab character
+        https://bugs.webkit.org/show_bug.cgi?id=145885
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Controllers/CodeMirrorCompletionController.js:
+        (WebInspector.CodeMirrorCompletionController):
+        (WebInspector.CodeMirrorCompletionController.prototype.updateCompletions): Resolves the promise as having completions.
+        (WebInspector.CodeMirrorCompletionController.prototype.hideCompletions): Resolves the promise as not having completions.
+        (WebInspector.CodeMirrorCompletionController.prototype.completeAtCurrentPositionIfNeeded): Returns a WrappedPromise that allows
+        callers of this function to determine if the autocomplete had any values or was instead not shown.
+        (WebInspector.CodeMirrorCompletionController.prototype._resolveUpdatePromise):
+        * UserInterface/Main.html: Added WrappedPromise class.
+        * UserInterface/Models/WrappedPromise.js: Added WrappedPromise object to expose resolve and reject functions.
+        * UserInterface/Views/ConsolePrompt.js:
+        (WebInspector.ConsolePrompt.prototype._handleTabKey): Attempts to find completions for current text.  If there are none, beep.
+
+2015-07-01  Devin Rousso  <drou...@apple.com>
+
         Make the first click on a rule section create a newline for easy property addition
         https://bugs.webkit.org/show_bug.cgi?id=146490
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js (186216 => 186217)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js	2015-07-02 04:01:03 UTC (rev 186216)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js	2015-07-02 04:30:53 UTC (rev 186217)
@@ -68,6 +68,8 @@
         this._codeMirror.on("cursorActivity", this._handleCursorActivityListener);
         this._codeMirror.on("blur", this._handleHideActionListener);
         this._codeMirror.on("scroll", this._handleHideActionListener);
+
+        this._updatePromise = null;
     }
 
     // Public
@@ -125,6 +127,8 @@
         }
 
         this._applyCompletionHint(completions[index]);
+
+        this._resolveUpdatePromise(WebInspector.CodeMirrorCompletionController.UpdatePromise.CompletionsFound);
     }
 
     isCompletionChange(change)
@@ -158,6 +162,8 @@
 
         delete this._currentCompletion;
         delete this._ignoreNextCursorActivity;
+
+        this._resolveUpdatePromise(WebInspector.CodeMirrorCompletionController.UpdatePromise.NoCompletionsFound);
     }
 
     close()
@@ -170,6 +176,17 @@
         this._codeMirror.off("scroll", this._handleHideActionListener);
     }
 
+    completeAtCurrentPositionIfNeeded(force)
+    {
+        this._resolveUpdatePromise(WebInspector.CodeMirrorCompletionController.UpdatePromise.Canceled);
+
+        var update = this._updatePromise = new WebInspector.WrappedPromise;
+
+        this._completeAtCurrentPosition(force);
+
+        return update.promise;
+    }
+
     // Protected
 
     completionSuggestionsSelectedCompletion(suggestionsView, completionText)
@@ -193,6 +210,15 @@
 
     // Private
 
+    _resolveUpdatePromise(message)
+    {
+        if (!this._updatePromise)
+            return;
+
+        this._updatePromise.resolve(message);
+        this._updatePromise = null;
+    }
+
     get _currentReplacementText()
     {
         return this._currentCompletion + this._implicitSuffix;
@@ -802,6 +828,12 @@
     }
 };
 
+WebInspector.CodeMirrorCompletionController.UpdatePromise = {
+    Canceled: "code-mirror-completion-controller-canceled",
+    CompletionsFound: "code-mirror-completion-controller-completions-found",
+    NoCompletionsFound: "code-mirror-completion-controller-no-completions-found"
+};
+
 WebInspector.CodeMirrorCompletionController.GenericStopCharactersRegex = /[\s=:;,]/;
 WebInspector.CodeMirrorCompletionController.DefaultStopCharactersRegexModeMap = {"css": /[\s:;,{}()]/, "_javascript_": /[\s=:;,!+\-*/%&|^~?<>.{}()[\]]/};
 WebInspector.CodeMirrorCompletionController.BaseExpressionStopCharactersRegexModeMap = {"_javascript_": /[\s=:;,!+\-*/%&|^~?<>]/};

Modified: trunk/Source/WebInspectorUI/UserInterface/Main.html (186216 => 186217)


--- trunk/Source/WebInspectorUI/UserInterface/Main.html	2015-07-02 04:01:03 UTC (rev 186216)
+++ trunk/Source/WebInspectorUI/UserInterface/Main.html	2015-07-02 04:30:53 UTC (rev 186217)
@@ -310,6 +310,7 @@
     <script src=""
     <script src=""
     <script src=""
+    <script src=""
 
     <script src=""
     <script src=""

Added: trunk/Source/WebInspectorUI/UserInterface/Models/WrappedPromise.js (0 => 186217)


--- trunk/Source/WebInspectorUI/UserInterface/Models/WrappedPromise.js	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/WrappedPromise.js	2015-07-02 04:30:53 UTC (rev 186217)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.WrappedPromise = class WrappedPromise
+{
+    constructor(work)
+    {
+        this._promise = new Promise(function(resolve, reject) {
+            this._resolve = resolve;
+            this._reject = reject;
+
+            if (work && typeof work === "function")
+                work();
+        }.bind(this));
+    }
+
+    // Public
+
+    get promise()
+    {
+        return this._promise;
+    }
+
+    resolve(value)
+    {
+        this._resolve(value);
+    }
+
+    reject(value)
+    {
+        this._reject(value);
+    }
+}
\ No newline at end of file

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ConsolePrompt.js (186216 => 186217)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ConsolePrompt.js	2015-07-02 04:01:03 UTC (rev 186216)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ConsolePrompt.js	2015-07-02 04:30:53 UTC (rev 186217)
@@ -51,6 +51,7 @@
         "Ctrl-N": this._handleNextKey.bind(this),
         "Enter": this._handleEnterKey.bind(this),
         "Cmd-Enter": this._handleCommandEnterKey.bind(this),
+        "Tab": this._handleTabKey.bind(this),
         "Esc": this._handleEscapeKey.bind(this)
     };
 
@@ -164,6 +165,14 @@
 
     // Private
 
+    _handleTabKey: function(codeMirror)
+    {
+        this._completionController.completeAtCurrentPositionIfNeeded().then(function(result) {
+            if (result === WebInspector.CodeMirrorCompletionController.UpdatePromise.NoCompletionsFound)
+                InspectorFrontendHost.beep();
+        });
+    },
+
     _handleEscapeKey: function(codeMirror)
     {
         if (this.text)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to