Title: [240412] branches/safari-607-branch/Source/WebInspectorUI
Revision
240412
Author
[email protected]
Date
2019-01-23 22:41:54 -0800 (Wed, 23 Jan 2019)

Log Message

Cherry-pick r239935. rdar://problem/47295382

    Web Inspector: Styles: pressing Down key on empty value field shouldn't discard completion popover
    https://bugs.webkit.org/show_bug.cgi?id=193098
    <rdar://problem/47016036>

    Reviewed by Devin Rousso.

    Hide CompletionSuggestionsView when SpreadsheetTextField moves, e.g. by scrolling or resizing the sidebar.
    Update CompletionSuggestionsView position after pressing Up or Down key, because SpreadsheetTextField may
    move from wrapping text.

    * UserInterface/Views/CompletionSuggestionsView.js:
    (WI.CompletionSuggestionsView.prototype.hide):
    (WI.CompletionSuggestionsView.prototype.show):
    (WI.CompletionSuggestionsView.prototype.showUntilAnchorMoves): Removed.
    (WI.CompletionSuggestionsView.prototype.hideWhenElementMoves): Added.
    (WI.CompletionSuggestionsView.prototype._stopMoveTimer): Added.
    (WI.CompletionSuggestionsView):

    * UserInterface/Views/SpreadsheetTextField.js:
    (WI.SpreadsheetTextField.prototype.set suggestionHint):
    (WI.SpreadsheetTextField.prototype.completionSuggestionsSelectedCompletion):
    (WI.SpreadsheetTextField.prototype._handleKeyDownForSuggestionView):
    (WI.SpreadsheetTextField.prototype._updateCompletions):
    (WI.SpreadsheetTextField.prototype._showSuggestionsView): Added.

    (WI.SpreadsheetTextField.prototype._reAttachSuggestionHint):
    Drive-by: abstract out repeating code into a private method.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239935 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-607-branch/Source/WebInspectorUI/ChangeLog (240411 => 240412)


--- branches/safari-607-branch/Source/WebInspectorUI/ChangeLog	2019-01-24 06:41:51 UTC (rev 240411)
+++ branches/safari-607-branch/Source/WebInspectorUI/ChangeLog	2019-01-24 06:41:54 UTC (rev 240412)
@@ -1,5 +1,70 @@
 2019-01-23  Alan Coon  <[email protected]>
 
+        Cherry-pick r239935. rdar://problem/47295382
+
+    Web Inspector: Styles: pressing Down key on empty value field shouldn't discard completion popover
+    https://bugs.webkit.org/show_bug.cgi?id=193098
+    <rdar://problem/47016036>
+    
+    Reviewed by Devin Rousso.
+    
+    Hide CompletionSuggestionsView when SpreadsheetTextField moves, e.g. by scrolling or resizing the sidebar.
+    Update CompletionSuggestionsView position after pressing Up or Down key, because SpreadsheetTextField may
+    move from wrapping text.
+    
+    * UserInterface/Views/CompletionSuggestionsView.js:
+    (WI.CompletionSuggestionsView.prototype.hide):
+    (WI.CompletionSuggestionsView.prototype.show):
+    (WI.CompletionSuggestionsView.prototype.showUntilAnchorMoves): Removed.
+    (WI.CompletionSuggestionsView.prototype.hideWhenElementMoves): Added.
+    (WI.CompletionSuggestionsView.prototype._stopMoveTimer): Added.
+    (WI.CompletionSuggestionsView):
+    
+    * UserInterface/Views/SpreadsheetTextField.js:
+    (WI.SpreadsheetTextField.prototype.set suggestionHint):
+    (WI.SpreadsheetTextField.prototype.completionSuggestionsSelectedCompletion):
+    (WI.SpreadsheetTextField.prototype._handleKeyDownForSuggestionView):
+    (WI.SpreadsheetTextField.prototype._updateCompletions):
+    (WI.SpreadsheetTextField.prototype._showSuggestionsView): Added.
+    
+    (WI.SpreadsheetTextField.prototype._reAttachSuggestionHint):
+    Drive-by: abstract out repeating code into a private method.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239935 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-01-14  Nikita Vasilyev  <[email protected]>
+
+            Web Inspector: Styles: pressing Down key on empty value field shouldn't discard completion popover
+            https://bugs.webkit.org/show_bug.cgi?id=193098
+            <rdar://problem/47016036>
+
+            Reviewed by Devin Rousso.
+
+            Hide CompletionSuggestionsView when SpreadsheetTextField moves, e.g. by scrolling or resizing the sidebar.
+            Update CompletionSuggestionsView position after pressing Up or Down key, because SpreadsheetTextField may
+            move from wrapping text.
+
+            * UserInterface/Views/CompletionSuggestionsView.js:
+            (WI.CompletionSuggestionsView.prototype.hide):
+            (WI.CompletionSuggestionsView.prototype.show):
+            (WI.CompletionSuggestionsView.prototype.showUntilAnchorMoves): Removed.
+            (WI.CompletionSuggestionsView.prototype.hideWhenElementMoves): Added.
+            (WI.CompletionSuggestionsView.prototype._stopMoveTimer): Added.
+            (WI.CompletionSuggestionsView):
+
+            * UserInterface/Views/SpreadsheetTextField.js:
+            (WI.SpreadsheetTextField.prototype.set suggestionHint):
+            (WI.SpreadsheetTextField.prototype.completionSuggestionsSelectedCompletion):
+            (WI.SpreadsheetTextField.prototype._handleKeyDownForSuggestionView):
+            (WI.SpreadsheetTextField.prototype._updateCompletions):
+            (WI.SpreadsheetTextField.prototype._showSuggestionsView): Added.
+
+            (WI.SpreadsheetTextField.prototype._reAttachSuggestionHint):
+            Drive-by: abstract out repeating code into a private method.
+
+2019-01-23  Alan Coon  <[email protected]>
+
         Cherry-pick r240051. rdar://problem/47458262
 
     Web Inspector: Fix TreeOutline TypeError:​ this._indexesForSubtree is not a function

Modified: branches/safari-607-branch/Source/WebInspectorUI/UserInterface/Views/CompletionSuggestionsView.js (240411 => 240412)


--- branches/safari-607-branch/Source/WebInspectorUI/UserInterface/Views/CompletionSuggestionsView.js	2019-01-24 06:41:51 UTC (rev 240411)
+++ branches/safari-607-branch/Source/WebInspectorUI/UserInterface/Views/CompletionSuggestionsView.js	2019-01-24 06:41:54 UTC (rev 240412)
@@ -33,7 +33,7 @@
         this._preventBlur = preventBlur || false;
 
         this._selectedIndex = NaN;
-        this._anchorBounds = null;
+        this._moveIntervalIdentifier = null;
 
         this._element = document.createElement("div");
         this._element.classList.add("completion-suggestions", WI.Popover.IgnoreAutoDismissClassName);
@@ -112,6 +112,8 @@
 
     show(anchorBounds)
     {
+        let scrollTop = this._containerElement.scrollTop;
+
         // Measure the container so we can know the intrinsic size of the items.
         this._containerElement.style.position = "absolute";
         document.body.appendChild(this._containerElement);
@@ -156,40 +158,30 @@
         this._element.style.height = height + "px";
 
         document.body.appendChild(this._element);
+
+        if (scrollTop)
+            this._containerElement.scrollTop = scrollTop;
     }
 
-    showUntilAnchorMoves(getAnchorBounds)
+    hide()
     {
-        this._anchorBounds = getAnchorBounds();
-        if (!this._anchorBounds) {
-            this.hide();
-            return;
-        }
+        this._element.remove();
+        this._stopMoveTimer();
+    }
 
-        this.show(this._anchorBounds);
+    hideWhenElementMoves(element)
+    {
+        this._stopMoveTimer();
+        let initialClientRect = element.getBoundingClientRect();
 
-        let hideWhenMoved = () => {
-            let anchorBounds = getAnchorBounds();
-            if (!anchorBounds || !anchorBounds.equals(this._anchorBounds))
+        this._moveIntervalIdentifier = setInterval(() => {
+            let clientRect = element.getBoundingClientRect();
+            if (clientRect.x !== initialClientRect.x || clientRect.y !== initialClientRect.y)
                 this.hide();
-        };
+        }, 200);
 
-        if (this._hideWhenMovedIdentifier)
-            clearInterval(this._hideWhenMovedIdentifier);
-
-        this._hideWhenMovedIdentifier = setInterval(hideWhenMoved, 200);
     }
 
-    hide()
-    {
-        this._element.remove();
-        this._anchorBounds = null;
-        if (this._hideWhenMovedIdentifier) {
-            clearInterval(this._hideWhenMovedIdentifier);
-            this._hideWhenMovedIdentifier = 0;
-        }
-    }
-
     update(completions, selectedIndex)
     {
         this._containerElement.removeChildren();
@@ -253,6 +245,15 @@
         if (this._delegate && typeof this._delegate.completionSuggestionsClickedCompletion === "function")
             this._delegate.completionSuggestionsClickedCompletion(this, itemElement.textContent);
     }
+
+    _stopMoveTimer()
+    {
+        if (!this._moveIntervalIdentifier)
+            return;
+
+        clearInterval(this._moveIntervalIdentifier);
+        this._moveIntervalIdentifier = null;
+    }
 };
 
 WI.CompletionSuggestionsView.ItemElementStyleClassName = "item";

Modified: branches/safari-607-branch/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js (240411 => 240412)


--- branches/safari-607-branch/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js	2019-01-24 06:41:51 UTC (rev 240411)
+++ branches/safari-607-branch/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js	2019-01-24 06:41:54 UTC (rev 240412)
@@ -74,10 +74,9 @@
     {
         this._suggestionHintElement.textContent = value;
 
-        if (value) {
-            if (this._suggestionHintElement.parentElement !== this._element)
-                this._element.append(this._suggestionHintElement);
-        } else
+        if (value)
+            this._reAttachSuggestionHint();
+        else
             this._suggestionHintElement.remove();
     }
 
@@ -144,8 +143,7 @@
 
         this.suggestionHint = selectedText.slice(completionPrefix.length);
 
-        if (this._suggestionHintElement.parentElement !== this._element)
-            this._element.append(this._suggestionHintElement);
+        this._reAttachSuggestionHint();
 
         if (this._delegate && typeof this._delegate.spreadsheetTextFieldDidChange === "function")
             this._delegate.spreadsheetTextFieldDidChange(this);
@@ -303,6 +301,9 @@
             else
                 this._suggestionsView.selectPrevious();
 
+            // Update popover position in case text moved, e.g. started or stopped wrapping.
+            this._showSuggestionsView();
+
             if (this._delegate && typeof this._delegate.spreadsheetTextFieldDidChange === "function")
                 this._delegate.spreadsheetTextFieldDidChange(this);
 
@@ -391,12 +392,8 @@
         if (completions.length === 1) {
             // No need to show the completion popover that matches the suggestion hint.
             this._suggestionsView.hide();
-        } else {
-            let startOffset = prefix.length - completionPrefix.length;
-            this._suggestionsView.showUntilAnchorMoves(() => {
-                return this._getCaretRect(startOffset);
-            });
-        }
+        } else
+            this._showSuggestionsView();
 
         this._suggestionsView.selectedIndex = NaN;
         if (completionPrefix) {
@@ -406,6 +403,22 @@
             this.suggestionHint = "";
     }
 
+    _showSuggestionsView()
+    {
+        let prefix = this.valueWithoutSuggestion();
+        let completionPrefix = this._getCompletionPrefix(prefix);
+        let startOffset = prefix.length - completionPrefix.length;
+        let caretRect = this._getCaretRect(startOffset);
+
+        // Hide completion popover when the anchor element is removed from the DOM.
+        if (!caretRect)
+            this._suggestionsView.hide();
+        else {
+            this._suggestionsView.show(caretRect);
+            this._suggestionsView.hideWhenElementMoves(this._element);
+        }
+    }
+
     _getCaretRect(startOffset)
     {
         let selection = window.getSelection();
@@ -451,4 +464,12 @@
 
         this._element.textContent = this._element.textContent;
     }
+
+    _reAttachSuggestionHint()
+    {
+        if (this._suggestionHintElement.parentElement === this._element)
+            return;
+
+        this._element.append(this._suggestionHintElement);
+    }
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to