Title: [208774] trunk/Source/WebInspectorUI
Revision
208774
Author
[email protected]
Date
2016-11-15 17:03:24 -0800 (Tue, 15 Nov 2016)

Log Message

REGRESSION (r208248): Web Inspector: Pressing Left Arrow breaks autocomplete
https://bugs.webkit.org/show_bug.cgi?id=164391
<rdar://problem/29102408>

Reviewed by Matt Baker.

Unroll r208248.

* UserInterface/Controllers/CodeMirrorCompletionController.js:
(WebInspector.CodeMirrorCompletionController):
(WebInspector.CodeMirrorCompletionController.prototype.updateCompletions):
(WebInspector.CodeMirrorCompletionController.prototype.isCompletionChange):
(WebInspector.CodeMirrorCompletionController.prototype.hideCompletions):
(WebInspector.CodeMirrorCompletionController.prototype.close):
(WebInspector.CodeMirrorCompletionController.prototype.completionSuggestionsSelectedCompletion):
(WebInspector.CodeMirrorCompletionController.prototype._createCompletionHintMarker):
(WebInspector.CodeMirrorCompletionController.prototype._applyCompletionHint.update):
(WebInspector.CodeMirrorCompletionController.prototype._applyCompletionHint):
(WebInspector.CodeMirrorCompletionController.prototype._commitCompletionHint.update):
(WebInspector.CodeMirrorCompletionController.prototype._commitCompletionHint):
(WebInspector.CodeMirrorCompletionController.prototype._removeLastChangeFromHistory):
(WebInspector.CodeMirrorCompletionController.prototype._removeCompletionHint.clearMarker):
(WebInspector.CodeMirrorCompletionController.prototype._removeCompletionHint.update):
(WebInspector.CodeMirrorCompletionController.prototype._removeCompletionHint):
(WebInspector.CodeMirrorCompletionController.prototype._completeAtCurrentPosition):
(WebInspector.CodeMirrorCompletionController.prototype._generateJavaScriptCompletions):

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (208773 => 208774)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-11-16 01:01:52 UTC (rev 208773)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-11-16 01:03:24 UTC (rev 208774)
@@ -1,3 +1,32 @@
+2016-11-15  Nikita Vasilyev  <[email protected]>
+
+        REGRESSION (r208248): Web Inspector: Pressing Left Arrow breaks autocomplete
+        https://bugs.webkit.org/show_bug.cgi?id=164391
+        <rdar://problem/29102408>
+
+        Reviewed by Matt Baker.
+
+        Unroll r208248.
+
+        * UserInterface/Controllers/CodeMirrorCompletionController.js:
+        (WebInspector.CodeMirrorCompletionController):
+        (WebInspector.CodeMirrorCompletionController.prototype.updateCompletions):
+        (WebInspector.CodeMirrorCompletionController.prototype.isCompletionChange):
+        (WebInspector.CodeMirrorCompletionController.prototype.hideCompletions):
+        (WebInspector.CodeMirrorCompletionController.prototype.close):
+        (WebInspector.CodeMirrorCompletionController.prototype.completionSuggestionsSelectedCompletion):
+        (WebInspector.CodeMirrorCompletionController.prototype._createCompletionHintMarker):
+        (WebInspector.CodeMirrorCompletionController.prototype._applyCompletionHint.update):
+        (WebInspector.CodeMirrorCompletionController.prototype._applyCompletionHint):
+        (WebInspector.CodeMirrorCompletionController.prototype._commitCompletionHint.update):
+        (WebInspector.CodeMirrorCompletionController.prototype._commitCompletionHint):
+        (WebInspector.CodeMirrorCompletionController.prototype._removeLastChangeFromHistory):
+        (WebInspector.CodeMirrorCompletionController.prototype._removeCompletionHint.clearMarker):
+        (WebInspector.CodeMirrorCompletionController.prototype._removeCompletionHint.update):
+        (WebInspector.CodeMirrorCompletionController.prototype._removeCompletionHint):
+        (WebInspector.CodeMirrorCompletionController.prototype._completeAtCurrentPosition):
+        (WebInspector.CodeMirrorCompletionController.prototype._generateJavaScriptCompletions):
+
 2016-11-15  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Remove unused and untested Page.setTouchEmulationEnabled command

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js (208773 => 208774)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js	2016-11-16 01:01:52 UTC (rev 208773)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js	2016-11-16 01:03:24 UTC (rev 208774)
@@ -58,7 +58,6 @@
             "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);
@@ -65,7 +64,6 @@
 
         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);
@@ -72,12 +70,6 @@
         this._codeMirror.on("scroll", this._handleHideActionListener);
 
         this._updatePromise = null;
-
-        this._currentCompletion = null;
-        this._ignoreChange = false;
-        this._ignoreNextCursorActivity = false;
-        this._ignoreNextUndo = false;
-        this._inCompletionActivity = false;
     }
 
     // Public
@@ -94,10 +86,8 @@
 
     updateCompletions(completions, implicitSuffix)
     {
-        if (isNaN(this._startOffset) || isNaN(this._endOffset) || isNaN(this._lineNumber)) {
-            this._inCompletionActivity = false;
+        if (isNaN(this._startOffset) || isNaN(this._endOffset) || isNaN(this._lineNumber))
             return;
-        }
 
         if (!completions || !completions.length) {
             this.hideCompletions();
@@ -143,7 +133,7 @@
 
     isCompletionChange(change)
     {
-        return this._ignoreChange || this._ignoreNextUndo || change.origin === WebInspector.CodeMirrorCompletionController.CompletionOrigin || change.origin === WebInspector.CodeMirrorCompletionController.DeleteCompletionOrigin;
+        return this._ignoreChange || change.origin === WebInspector.CodeMirrorCompletionController.CompletionOrigin || change.origin === WebInspector.CodeMirrorCompletionController.DeleteCompletionOrigin;
     }
 
     isShowingCompletions()
@@ -170,9 +160,8 @@
         this._implicitSuffix = "";
         this._forced = false;
 
-        this._currentCompletion = null;
-        this._ignoreNextCursorActivity = false;
-        this._inCompletionActivity = false;
+        delete this._currentCompletion;
+        delete this._ignoreNextCursorActivity;
 
         this._resolveUpdatePromise(WebInspector.CodeMirrorCompletionController.UpdatePromise.NoCompletionsFound);
     }
@@ -181,7 +170,6 @@
     {
         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);
@@ -203,8 +191,6 @@
 
     completionSuggestionsSelectedCompletion(suggestionsView, completionText)
     {
-        this._ignoreNextUndo = true;
-
         this._applyCompletionHint(completionText);
     }
 
@@ -259,6 +245,15 @@
         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,26 +262,17 @@
 
         function update()
         {
-            if (!this._inCompletionActivity) {
-                this._inCompletionActivity = true;
-                this._codeMirror.changeGeneration(true);
-            }
-
             this._currentCompletion = completionText;
 
-            this._removeCompletionHint(true);
+            this._removeCompletionHint(true, true);
 
-            let replacementText = this._currentReplacementText;
+            var replacementText = this._currentReplacementText;
 
-            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};
+            var from = {line: this._lineNumber, ch: this._startOffset};
+            var cursor = {line: this._lineNumber, ch: this._endOffset};
+            var currentText = this._codeMirror.getRange(from, cursor);
 
-            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._createCompletionHintMarker(cursor, replacementText.replace(currentText, ""));
         }
 
         this._ignoreChange = true;
@@ -294,7 +280,7 @@
 
         this._codeMirror.operation(update.bind(this));
 
-        this._ignoreChange = false;
+        delete this._ignoreChange;
     }
 
     _commitCompletionHint()
@@ -301,7 +287,7 @@
     {
         function update()
         {
-            this._removeCompletionHint(true);
+            this._removeCompletionHint(true, true);
 
             var replacementText = this._currentReplacementText;
 
@@ -316,6 +302,8 @@
 
             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();
@@ -326,35 +314,71 @@
 
         this._codeMirror.operation(update.bind(this));
 
-        this._ignoreChange = false;
+        delete this._ignoreChange;
     }
 
-    _removeCompletionHint(nonatomic)
+    _removeLastChangeFromHistory()
     {
+        var history = this._codeMirror.getHistory();
+
+        // We don't expect a undone history. But if there is one clear it. If could lead to undefined behavior.
+        console.assert(!history.undone.length);
+        history.undone = [];
+
+        // Pop the last item from the done history.
+        console.assert(history.done.length);
+        history.done.pop();
+
+        this._codeMirror.setHistory(history);
+    }
+
+    _removeCompletionHint(nonatomic, dontRestorePrefix)
+    {
         if (!this._completionHintMarker)
             return;
 
         this._notifyCompletionsHiddenSoon();
 
-        function update()
+        function clearMarker(marker)
         {
-            this._codeMirror.undo();
+            if (!marker)
+                return;
 
-            let range = this._completionHintMarker.find();
+            var range = marker.find();
             if (range)
-                this._completionHintMarker.clear();
+                marker.clear();
 
-            this._completionHintMarker = null;
+            return null;
         }
 
-        this._ignoreChange = true;
+        function update()
+        {
+            this._completionHintMarker = clearMarker(this._completionHintMarker);
 
-        if (nonatomic)
+            if (dontRestorePrefix)
+                return;
+
+            console.assert(!isNaN(this._startOffset));
+            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};
+
+            this._codeMirror.replaceRange(this._prefix, from, to, WebInspector.CodeMirrorCompletionController.DeleteCompletionOrigin);
+            this._removeLastChangeFromHistory();
+        }
+
+        if (nonatomic) {
             update.call(this);
-        else
-            this._codeMirror.operation(update.bind(this));
+            return;
+        }
 
-        this._ignoreChange = false;
+        this._ignoreChange = true;
+
+        this._codeMirror.operation(update.bind(this));
+
+        delete this._ignoreChange;
     }
 
     _scanStringForExpression(modeName, string, startOffset, direction, allowMiddleAndEmpty, includeStopCharacter, ignoreInitialUnmatchedOpenBracket, stopCharactersRegex)
@@ -438,7 +462,7 @@
             return;
         }
 
-        this._removeCompletionHint(true);
+        this._removeCompletionHint(true, true);
 
         var cursor = this._codeMirror.getCursor();
         var token = this._codeMirror.getTokenAt(cursor);
@@ -783,17 +807,6 @@
         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))
@@ -801,11 +814,6 @@
 
         this._ignoreNextCursorActivity = true;
 
-        if (this._ignoreNextUndo && change.origin === "undo") {
-            this._ignoreNextUndo = false;
-            return;
-        }
-
         if (!change.origin || change.origin.charAt(0) !== "+") {
             this.hideCompletions();
             return;
@@ -824,7 +832,7 @@
             return;
 
         if (this._ignoreNextCursorActivity) {
-            this._ignoreNextCursorActivity = false;
+            delete this._ignoreNextCursorActivity;
             return;
         }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to