Changeset 244154 in webkit


Ignore:
Timestamp:
Apr 10, 2019 3:44:11 PM (5 years ago)
Author:
Devin Rousso
Message:

Web Inspector: Elements tab: multiple selection lost after navigating to another tab
https://bugs.webkit.org/show_bug.cgi?id=192681
<rdar://problem/46709392>

Reviewed by Timothy Hatcher.

Orginal patch by Matt Baker <Matt Baker>.

Source/WebInspectorUI:

  • UserInterface/Controllers/SelectionController.js:

(WI.SelectionController.prototype.selectItem):
Simplify internal logic by removing an early return.

(WI.SelectionController.prototype.selectItems): Added.
(WI.SelectionController.prototype.selectAll):
Provide a means to select multiple items in a single operation.
If _lastSelectedItem is not in the items to select, the last
item being selected will become the last selected item.

(WI.SelectionController.prototype._deselectAllAndSelect):
Drive-by fix: correct a logic error. If no items are selected, the item
passed as an argument should still become selected.

  • UserInterface/Views/TreeOutline.js:

(WI.TreeOutline.prototype.selectTreeElements): Added.

  • UserInterface/Views/DOMTreeElement.js:

(WI.DOMTreeElement):
(WI.DOMTreeElement.prototype.get closeTagTreeElement): Added.
(WI.DOMTreeElement.prototype._updateChildren):
Make the close tag TreeElement available from the open tag TreeElement.

  • UserInterface/Views/DOMTreeOutline.js:

(WI.DOMTreeOutline.prototype.update):
Restore selected TreeElements after updating.

  • UserInterface/Base/Utilities.js:
  • UserInterface/Test.html:

LayoutTests:

  • inspector/tree-outline/tree-outline-selection.html: Added.
  • inspector/tree-outline/tree-outline-selection-expected.txt: Added.

Add TreeOutline tests for single and multiple selection.

  • inspector/unit-tests/set-utilities.html:
  • inspector/unit-tests/set-utilities-expected.txt:

Add tests for Set.prototype.lastValue.

Location:
trunk
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r244150 r244154  
     12019-04-10  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Elements tab: multiple selection lost after navigating to another tab
     4        https://bugs.webkit.org/show_bug.cgi?id=192681
     5        <rdar://problem/46709392>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        Orginal patch by Matt Baker <mattbaker@apple.com>.
     10
     11        * inspector/tree-outline/tree-outline-selection.html: Added.
     12        * inspector/tree-outline/tree-outline-selection-expected.txt: Added.
     13        Add `TreeOutline` tests for single and multiple selection.
     14
     15        * inspector/unit-tests/set-utilities.html:
     16        * inspector/unit-tests/set-utilities-expected.txt:
     17        Add tests for `Set.prototype.lastValue`.
     18
    1192019-04-10  Youenn Fablet  <youenn@apple.com>
    220
  • trunk/LayoutTests/inspector/unit-tests/set-utilities-expected.txt

    r242562 r244154  
    4242PASS: Set with values [1,2,3] should have firstValue equal to 1.
    4343
     44-- Running test case: Set.prototype.lastValue
     45PASS: Set with values [] should have lastValue equal to undefined.
     46PASS: Set with values [1,2,3] should have lastValue equal to 3.
     47
  • trunk/LayoutTests/inspector/unit-tests/set-utilities.html

    r242562 r244154  
    123123        test() {
    124124            function testFirstValue(values) {
    125                 InspectorTest.expectEqual(new Set(values).firstValue, values[0], `Set with values [${values}] should have firstValue equal to ${values[0]}.`);
     125                let expected = values[0];
     126                InspectorTest.expectEqual(new Set(values).firstValue, expected, `Set with values [${values}] should have firstValue equal to ${expected}.`);
    126127            }
    127128
    128129            testFirstValue([]);
    129130            testFirstValue([1, 2, 3]);
     131        }
     132    });
     133
     134    suite.addTestCase({
     135        name: "Set.prototype.lastValue",
     136        test() {
     137            function testLastValue(values) {
     138                let expected = values.lastValue;
     139                InspectorTest.expectEqual(new Set(values).lastValue, expected, `Set with values [${values}] should have lastValue equal to ${expected}.`);
     140            }
     141
     142            testLastValue([]);
     143            testLastValue([1, 2, 3]);
    130144        }
    131145    });
  • trunk/Source/WebInspectorUI/ChangeLog

    r244063 r244154  
     12019-04-10  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Elements tab: multiple selection lost after navigating to another tab
     4        https://bugs.webkit.org/show_bug.cgi?id=192681
     5        <rdar://problem/46709392>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        Orginal patch by Matt Baker <mattbaker@apple.com>.
     10
     11        * UserInterface/Controllers/SelectionController.js:
     12        (WI.SelectionController.prototype.selectItem):
     13        Simplify internal logic by removing an early return.
     14
     15        (WI.SelectionController.prototype.selectItems): Added.
     16        (WI.SelectionController.prototype.selectAll):
     17        Provide a means to select multiple items in a single operation.
     18        If `_lastSelectedItem` is not in the items to select, the last
     19        item being selected will become the last selected item.
     20
     21        (WI.SelectionController.prototype._deselectAllAndSelect):
     22        Drive-by fix: correct a logic error. If no items are selected, the item
     23        passed as an argument should still become selected.
     24
     25        * UserInterface/Views/TreeOutline.js:
     26        (WI.TreeOutline.prototype.selectTreeElements): Added.
     27
     28        * UserInterface/Views/DOMTreeElement.js:
     29        (WI.DOMTreeElement):
     30        (WI.DOMTreeElement.prototype.get closeTagTreeElement): Added.
     31        (WI.DOMTreeElement.prototype._updateChildren):
     32        Make the close tag `TreeElement` available from the open tag `TreeElement`.
     33
     34        * UserInterface/Views/DOMTreeOutline.js:
     35        (WI.DOMTreeOutline.prototype.update):
     36        Restore selected `TreeElement`s after updating.
     37
     38        * UserInterface/Base/Utilities.js:
     39        * UserInterface/Test.html:
     40
    1412019-04-08  Matt Baker  <mattbaker@apple.com>
    242
  • trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js

    r243242 r244154  
    167167});
    168168
     169Object.defineProperty(Set.prototype, "lastValue",
     170{
     171    get()
     172    {
     173        return Array.from(this.values()).lastValue;
     174    }
     175});
     176
    169177Object.defineProperty(Set.prototype, "intersects",
    170178{
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/SelectionController.js

    r241652 r244154  
    8989            extendSelection = false;
    9090
    91         if (this.hasSelectedItem(item)) {
    92             if (!extendSelection)
    93                 this._deselectAllAndSelect(item);
    94             return;
    95         }
    96 
    9791        this._lastSelectedItem = item;
    9892        this._shiftAnchorItem = null;
     
    10296
    10397        this._updateSelectedItems(newItems);
     98    }
     99
     100    selectItems(items)
     101    {
     102        console.assert(this._allowsMultipleSelection, "Cannot select multiple items with multiple selection disabled.");
     103        if (!this._allowsMultipleSelection)
     104            return;
     105
     106        if (!this._lastSelectedItem || !items.has(this._lastSelectedItem))
     107            this._lastSelectedItem = items.lastValue;
     108
     109        if (!this._shiftAnchorItem || !items.has(this._shiftAnchorItem))
     110            this._shiftAnchorItem = this._lastSelectedItem;
     111
     112        this._updateSelectedItems(items);
    104113    }
    105114
     
    151160            return;
    152161
    153         this._lastSelectedItem = this._lastSelectableItem();
     162        this.reset();
    154163
    155164        let newItems = new Set;
    156         this._addRange(newItems, this._firstSelectableItem(), this._lastSelectedItem);
    157 
    158         if (!this._shiftAnchorItem)
    159             this._shiftAnchorItem = this._lastSelectedItem;
    160 
    161         this._updateSelectedItems(newItems);
     165        this._addRange(newItems, this._firstSelectableItem(), this._lastSelectableItem());
     166        this.selectItems(newItems);
    162167    }
    163168
     
    298303    _deselectAllAndSelect(item)
    299304    {
    300         if (!this._selectedItems.size)
     305        if (!this._selectedItems.size && !item)
    301306            return;
    302307
  • trunk/Source/WebInspectorUI/UserInterface/Test.html

    r243355 r244154  
    262262    <script src="Views/Table.js"></script>
    263263    <script src="Views/TableColumn.js"></script>
     264    <script src="Views/TreeElement.js"></script>
     265    <script src="Views/TreeOutline.js"></script>
    264266
    265267    <script type="text/javascript">
  • trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js

    r243152 r244154  
    5050        this._highlightedAttributes = new Set;
    5151        this._recentlyModifiedAttributes = new Map;
     52        this._closeTagTreeElement = null;
    5253
    5354        node.addEventListener(WI.DOMNode.Event.EnabledPseudoClassesChanged, this._nodePseudoClassesDidChange, this);
     
    106107        }
    107108    }
     109
     110    get closeTagTreeElement() { return this._closeTagTreeElement; }
    108111
    109112    revealAndHighlight()
     
    460463            return;
    461464
     465        this._closeTagTreeElement = null;
    462466        this._updateChildrenInProgress = true;
    463467
     
    535539        var lastChild = this.children.lastValue;
    536540        if (node.nodeType() === Node.ELEMENT_NODE && (!lastChild || !lastChild._elementCloseTag))
    537             this.insertChildElement(this.representedObject, this.children.length, true);
     541            this._closeTagTreeElement = this.insertChildElement(this.representedObject, this.children.length, true);
    538542
    539543        // We want to restore the original selection and tree scroll position after a full refresh, if possible.
  • trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeOutline.js

    r242577 r244154  
    159159            return;
    160160
    161         let selectedNode = this.selectedTreeElement ? this.selectedTreeElement.representedObject : null;
     161        let selectedTreeElements = this.selectedTreeElements;
    162162
    163163        this.removeChildren();
     
    182182        }
    183183
    184         if (selectedNode)
    185             this._revealAndSelectNode(selectedNode, true);
     184        if (!selectedTreeElements.length)
     185            return;
     186
     187        // The selection cannot be restored from represented objects alone,
     188        // since a closing tag DOMTreeElement has the same represented object
     189        // as its parent.
     190        selectedTreeElements = selectedTreeElements.map((oldTreeElement) => {
     191            let treeElement = this.findTreeElement(oldTreeElement.representedObject);
     192            if (treeElement && oldTreeElement.isCloseTag()) {
     193                console.assert(treeElement.closeTagTreeElement, "Missing close tag TreeElement.", treeElement);
     194                if (treeElement.closeTagTreeElement)
     195                    treeElement = treeElement.closeTagTreeElement;
     196            }
     197            return treeElement;
     198        });
     199
     200        this.selectTreeElements(selectedTreeElements);
     201        this.selectedTreeElement.reveal();
    186202    }
    187203
  • trunk/Source/WebInspectorUI/UserInterface/Views/TreeOutline.js

    r243242 r244154  
    712712    }
    713713
     714    selectTreeElements(treeElements)
     715    {
     716        if (!treeElements.length)
     717            return;
     718
     719        if (treeElements.length === 1) {
     720            this.selectedTreeElement = treeElements[0];
     721            return;
     722        }
     723
     724        console.assert(this.allowsMultipleSelection, "Cannot select TreeElements with multiple selection disabled.");
     725        if (!this.allowsMultipleSelection)
     726            return;
     727
     728        let selectableObjects = treeElements.map((treeElement) => this.objectForSelection(treeElement));
     729        this._selectionController.selectItems(new Set(selectableObjects));
     730    }
     731
    714732    get selectedTreeElementIndex()
    715733    {
Note: See TracChangeset for help on using the changeset viewer.