Changeset 228487 in webkit


Ignore:
Timestamp:
Feb 14, 2018 2:45:50 PM (6 years ago)
Author:
Nikita Vasilyev
Message:

Web Inspector: Styles: completion popover doesn't hide when switching panels
https://bugs.webkit.org/show_bug.cgi?id=182464
<rdar://problem/37202763>

Reviewed by Timothy Hatcher.

Save the position of the anchor, an element the popover is shown for, and hide the completion popover
when the position changes.

  • UserInterface/Views/CompletionSuggestionsView.js:

(WI.CompletionSuggestionsView.prototype.showUntilAnchorMoves):
When the popover is visible, check every 200ms if the anchor moved.

(WI.CompletionSuggestionsView.prototype.hide):

  • UserInterface/Views/SpreadsheetTextField.js:

(WI.SpreadsheetTextField.prototype._updateCompletions):
(WI.SpreadsheetTextField.prototype._getCaretRect):
getBoundingClientRect returns {x: 0, y: 0} when it can't determine node's position.
This happens when a node isn't attached to DOM, attached to DOM but not visible, and
a number of odd cases.

Location:
trunk/Source/WebInspectorUI
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r228479 r228487  
     12018-02-14  Nikita Vasilyev  <nvasilyev@apple.com>
     2
     3        Web Inspector: Styles: completion popover doesn't hide when switching panels
     4        https://bugs.webkit.org/show_bug.cgi?id=182464
     5        <rdar://problem/37202763>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        Save the position of the anchor, an element the popover is shown for, and hide the completion popover
     10        when the position changes.
     11
     12        * UserInterface/Views/CompletionSuggestionsView.js:
     13        (WI.CompletionSuggestionsView.prototype.showUntilAnchorMoves):
     14        When the popover is visible, check every 200ms if the anchor moved.
     15
     16        (WI.CompletionSuggestionsView.prototype.hide):
     17        * UserInterface/Views/SpreadsheetTextField.js:
     18        (WI.SpreadsheetTextField.prototype._updateCompletions):
     19        (WI.SpreadsheetTextField.prototype._getCaretRect):
     20        getBoundingClientRect returns {x: 0, y: 0} when it can't determine node's position.
     21        This happens when a node isn't attached to DOM, attached to DOM but not visible, and
     22        a number of odd cases.
     23
    1242018-02-14  Matt Baker  <mattbaker@apple.com>
    225
  • trunk/Source/WebInspectorUI/UserInterface/Views/CompletionSuggestionsView.js

    r223283 r228487  
    3434
    3535        this._selectedIndex = NaN;
     36        this._anchorBounds = null;
    3637
    3738        this._element = document.createElement("div");
     
    158159    }
    159160
     161    showUntilAnchorMoves(getAnchorBounds)
     162    {
     163        this._anchorBounds = getAnchorBounds();
     164        if (!this._anchorBounds) {
     165            this.hide();
     166            return;
     167        }
     168
     169        this.show(this._anchorBounds);
     170
     171        let hideWhenMoved = () => {
     172            let anchorBounds = getAnchorBounds();
     173            if (!anchorBounds || !anchorBounds.equals(this._anchorBounds))
     174                this.hide();
     175        };
     176
     177        if (this._hideWhenMovedIdentifier)
     178            clearInterval(this._hideWhenMovedIdentifier);
     179
     180        this._hideWhenMovedIdentifier = setInterval(hideWhenMoved, 200);
     181    }
     182
    160183    hide()
    161184    {
    162185        this._element.remove();
     186        this._anchorBounds = null;
     187        if (this._hideWhenMovedIdentifier) {
     188            clearInterval(this._hideWhenMovedIdentifier);
     189            this._hideWhenMovedIdentifier = 0;
     190        }
    163191    }
    164192
  • trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js

    r227585 r228487  
    378378            this._suggestionsView.hide();
    379379        } else {
    380             let caretRect = this._getCaretRect(prefix, completionPrefix);
    381             this._suggestionsView.show(caretRect);
     380            let startOffset = prefix.length - completionPrefix.length;
     381            this._suggestionsView.showUntilAnchorMoves(() => {
     382                return this._getCaretRect(startOffset);
     383            });
    382384        }
    383385
     
    390392    }
    391393
    392     _getCaretRect(prefix, completionPrefix)
    393     {
    394         let startOffset = prefix.length - completionPrefix.length;
     394    _getCaretRect(startOffset)
     395    {
    395396        let selection = window.getSelection();
    396397
    397         if (startOffset > 0 && selection.rangeCount) {
     398        let isHidden = (clientRect) => {
     399            return clientRect.x === 0 && clientRect.y === 0
     400        };
     401
     402        if (selection.rangeCount) {
    398403            let range = selection.getRangeAt(0).cloneRange();
    399404            range.setStart(range.startContainer, startOffset);
    400405            let clientRect = range.getBoundingClientRect();
    401             return WI.Rect.rectFromClientRect(clientRect);
     406
     407            if (!isHidden(clientRect)) {
     408                // This happens after deleting value. However, when focusing
     409                // on an empty value clientRect is visible.
     410                return WI.Rect.rectFromClientRect(clientRect);
     411            }
    402412        }
    403413
    404414        let clientRect = this._element.getBoundingClientRect();
     415        if (isHidden(clientRect))
     416            return null;
     417
    405418        const leftPadding = parseInt(getComputedStyle(this._element).paddingLeft) || 0;
    406419        return new WI.Rect(clientRect.left + leftPadding, clientRect.top, clientRect.width, clientRect.height);
Note: See TracChangeset for help on using the changeset viewer.