Title: [191419] trunk/Source/WebInspectorUI
Revision
191419
Author
commit-qu...@webkit.org
Date
2015-10-21 17:31:23 -0700 (Wed, 21 Oct 2015)

Log Message

Web Inspector: Autocompletion previews in the CSS sidebar do not apply
https://bugs.webkit.org/show_bug.cgi?id=147720

Patch by Devin Rousso <dcrousso+web...@gmail.com> on 2015-10-21
Reviewed by Timothy Hatcher.

When autocompletion hints are added to styles or the console, the history
object used by CodeMirror was edited to remove the last entry. Instead of
using this method (which caused glitchy behaviour when undo-ing), call
CodeMirror.undo() and adjust accordingly. In addition, a marker was being
used as the completion hint instead of applying text, whereas these
changes use actual text, ensuring that completions are previewed in the page.

* UserInterface/Controllers/CodeMirrorCompletionController.js:
(WebInspector.CodeMirrorCompletionController):
(WebInspector.CodeMirrorCompletionController.prototype.close):
(WebInspector.CodeMirrorCompletionController.prototype._applyCompletionHint.update):
(WebInspector.CodeMirrorCompletionController.prototype._commitCompletionHint.update):
(WebInspector.CodeMirrorCompletionController.prototype._removeCompletionHint.update):
(WebInspector.CodeMirrorCompletionController.prototype._removeCompletionHint):
(WebInspector.CodeMirrorCompletionController.prototype._handleBeforeChange):
(WebInspector.CodeMirrorCompletionController.prototype._createCompletionHintMarker): Deleted.
(WebInspector.CodeMirrorCompletionController.prototype._removeCompletionHint.clearMarker): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (191418 => 191419)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-10-22 00:29:51 UTC (rev 191418)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-10-22 00:31:23 UTC (rev 191419)
@@ -1,5 +1,30 @@
 2015-10-21  Devin Rousso  <dcrousso+web...@gmail.com>
 
+        Web Inspector: Autocompletion previews in the CSS sidebar do not apply
+        https://bugs.webkit.org/show_bug.cgi?id=147720
+
+        Reviewed by Timothy Hatcher.
+
+        When autocompletion hints are added to styles or the console, the history
+        object used by CodeMirror was edited to remove the last entry. Instead of
+        using this method (which caused glitchy behaviour when undo-ing), call
+        CodeMirror.undo() and adjust accordingly. In addition, a marker was being
+        used as the completion hint instead of applying text, whereas these
+        changes use actual text, ensuring that completions are previewed in the page.
+
+        * UserInterface/Controllers/CodeMirrorCompletionController.js:
+        (WebInspector.CodeMirrorCompletionController):
+        (WebInspector.CodeMirrorCompletionController.prototype.close):
+        (WebInspector.CodeMirrorCompletionController.prototype._applyCompletionHint.update):
+        (WebInspector.CodeMirrorCompletionController.prototype._commitCompletionHint.update):
+        (WebInspector.CodeMirrorCompletionController.prototype._removeCompletionHint.update):
+        (WebInspector.CodeMirrorCompletionController.prototype._removeCompletionHint):
+        (WebInspector.CodeMirrorCompletionController.prototype._handleBeforeChange):
+        (WebInspector.CodeMirrorCompletionController.prototype._createCompletionHintMarker): Deleted.
+        (WebInspector.CodeMirrorCompletionController.prototype._removeCompletionHint.clearMarker): Deleted.
+
+2015-10-21  Devin Rousso  <dcrousso+web...@gmail.com>
+
         Web Inspector: Add forgotten WebInspector.UIString from r190521
         https://bugs.webkit.org/show_bug.cgi?id=150425
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js (191418 => 191419)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js	2015-10-22 00:29:51 UTC (rev 191418)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js	2015-10-22 00:31:23 UTC (rev 191419)
@@ -59,12 +59,14 @@
             "Cmd-Y": this._handleHideKey.bind(this)
         };
 
+        this._handleBeforeChangeListener = this._handleBeforeChange.bind(this);
         this._handleChangeListener = this._handleChange.bind(this);
         this._handleCursorActivityListener = this._handleCursorActivity.bind(this);
         this._handleHideActionListener = this._handleHideAction.bind(this);
 
         this._codeMirror.addKeyMap(this._keyMap);
 
+        this._codeMirror.on("beforeChange", this._handleBeforeChangeListener);
         this._codeMirror.on("change", this._handleChangeListener);
         this._codeMirror.on("cursorActivity", this._handleCursorActivityListener);
         this._codeMirror.on("blur", this._handleHideActionListener);
@@ -171,6 +173,7 @@
     {
         this._codeMirror.removeKeyMap(this._keyMap);
 
+        this._codeMirror.off("beforeChange", this._handleBeforeChangeListener);
         this._codeMirror.off("change", this._handleChangeListener);
         this._codeMirror.off("cursorActivity", this._handleCursorActivityListener);
         this._codeMirror.off("blur", this._handleHideActionListener);
@@ -246,15 +249,6 @@
         this._notifyCompletionsHiddenIfNeededTimeout = setTimeout(notify.bind(this), WebInspector.CodeMirrorCompletionController.CompletionsHiddenDelay);
     }
 
-    _createCompletionHintMarker(position, text)
-    {
-        var container = document.createElement("span");
-        container.classList.add(WebInspector.CodeMirrorCompletionController.CompletionHintStyleClassName);
-        container.textContent = text;
-
-        this._completionHintMarker = this._codeMirror.setUniqueBookmark(position, {widget: container, insertLeft: true});
-    }
-
     _applyCompletionHint(completionText)
     {
         console.assert(completionText);
@@ -267,13 +261,17 @@
 
             this._removeCompletionHint(true, true);
 
-            var replacementText = this._currentReplacementText;
+            let replacementText = this._currentReplacementText;
 
-            var from = {line: this._lineNumber, ch: this._startOffset};
-            var cursor = {line: this._lineNumber, ch: this._endOffset};
-            var currentText = this._codeMirror.getRange(from, cursor);
+            let from = {line: this._lineNumber, ch: this._startOffset};
+            let cursor = {line: this._lineNumber, ch: this._endOffset};
+            let to = {line: this._lineNumber, ch: this._startOffset + replacementText.length};
 
-            this._createCompletionHintMarker(cursor, replacementText.replace(currentText, ""));
+            this._codeMirror.replaceRange(replacementText, from, cursor, WebInspector.CodeMirrorCompletionController.CompletionOrigin);
+
+            this._codeMirror.setCursor(cursor);
+            if (cursor.ch !== to.ch)
+                this._completionHintMarker = this._codeMirror.markText(cursor, to, {className: WebInspector.CodeMirrorCompletionController.CompletionHintStyleClassName});
         }
 
         this._ignoreChange = true;
@@ -303,8 +301,6 @@
 
             this._codeMirror.replaceRange(replacementText, from, cursor, WebInspector.CodeMirrorCompletionController.CompletionOrigin);
 
-            // Don't call _removeLastChangeFromHistory here to allow the committed completion to be undone.
-
             this._codeMirror.setCursor(to);
 
             this.hideCompletions();
@@ -340,22 +336,16 @@
 
         this._notifyCompletionsHiddenSoon();
 
-        function clearMarker(marker)
+        function update()
         {
-            if (!marker)
-                return;
+            this._codeMirror.undo();
 
-            var range = marker.find();
+            let range = this._completionHintMarker.find();
             if (range)
-                marker.clear();
+                this._completionHintMarker.clear();
 
-            return null;
-        }
+            this._completionHintMarker = null;
 
-        function update()
-        {
-            this._completionHintMarker = clearMarker(this._completionHintMarker);
-
             if (dontRestorePrefix)
                 return;
 
@@ -363,8 +353,8 @@
             console.assert(!isNaN(this._endOffset));
             console.assert(!isNaN(this._lineNumber));
 
-            var from = {line: this._lineNumber, ch: this._startOffset};
-            var to = {line: this._lineNumber, ch: this._endOffset};
+            let from = {line: this._lineNumber, ch: this._startOffset};
+            let to = {line: this._lineNumber, ch: this._endOffset};
 
             this._codeMirror.replaceRange(this._prefix, from, to, WebInspector.CodeMirrorCompletionController.DeleteCompletionOrigin);
             this._removeLastChangeFromHistory();
@@ -800,6 +790,17 @@
         this._applyCompletionHint(this._currentCompletion);
     }
 
+    _handleBeforeChange(codeMirror, change)
+    {
+        if (this.isCompletionChange(change))
+            return;
+
+        this._ignoreNextCursorActivity = true;
+
+        if (this.isShowingCompletions())
+            this.hideCompletions();
+    }
+
     _handleChange(codeMirror, change)
     {
         if (this.isCompletionChange(change))
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to