Web Inspector: Elements tab: selection is broken after deleting the selected node
authormattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Feb 2019 00:55:28 +0000 (00:55 +0000)
committermattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Feb 2019 00:55:28 +0000 (00:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194300
<rdar://problem/47829275>

Reviewed by Devin Rousso.

Deleting a TreeElement can cause an IndexSet including indexes
outside the deleted range to be passed to SelectionController,
corrupting the internal selection state.

* UserInterface/Views/TreeOutline.js:
(WI.TreeOutline.prototype._indexesForSubtree.numberOfElementsInSubtree): Added.
(WI.TreeOutline.prototype._indexesForSubtree):
Finding the last (rightmost leaf) TreeElement in the subtree used
TreeElement.prototype.traverseNextElement to do a depth first traversal.
This method did not stay within the subtree rooted at `treeElement`.

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/TreeOutline.js

index 56b3383..ddc685a 100644 (file)
@@ -1,5 +1,24 @@
 2019-02-05  Matt Baker  <mattbaker@apple.com>
 
+        Web Inspector: Elements tab: selection is broken after deleting the selected node
+        https://bugs.webkit.org/show_bug.cgi?id=194300
+        <rdar://problem/47829275>
+
+        Reviewed by Devin Rousso.
+
+        Deleting a TreeElement can cause an IndexSet including indexes
+        outside the deleted range to be passed to SelectionController,
+        corrupting the internal selection state.
+
+        * UserInterface/Views/TreeOutline.js:
+        (WI.TreeOutline.prototype._indexesForSubtree.numberOfElementsInSubtree): Added.
+        (WI.TreeOutline.prototype._indexesForSubtree):
+        Finding the last (rightmost leaf) TreeElement in the subtree used
+        TreeElement.prototype.traverseNextElement to do a depth first traversal.
+        This method did not stay within the subtree rooted at `treeElement`.
+
+2019-02-05  Matt Baker  <mattbaker@apple.com>
+
         Web Inspector: REGRESSION (r240947): Resources tab: can't select main frame after refreshing page
         https://bugs.webkit.org/show_bug.cgi?id=194254
         <rdar://problem/47805023>
index 4ef3e86..9f21a2c 100644 (file)
@@ -1089,26 +1089,25 @@ WI.TreeOutline = class TreeOutline extends WI.Object
         if (!treeOutline)
             return null;
 
-        let firstChild = treeElement.children[0];
-        if (treeElement.root && !firstChild)
-            return null;
-
-        let current = firstChild || treeElement;
-        let startIndex = treeOutline._indexOfTreeElement(current);
-        let endIndex = startIndex;
-
-        const skipUnrevealed = false;
-        const stayWithin = treeElement;
-        const dontPopulate = true;
-
-        while (current = current.traverseNextTreeElement(skipUnrevealed, stayWithin, dontPopulate))
-            endIndex++;
+        function numberOfElementsInSubtree(treeElement) {
+            let elements = treeElement.root ? Array.from(treeElement.children) : [treeElement];
+            let count = 0;
+            while (elements.length) {
+                let child = elements.pop();
+                if (child.hidden)
+                    continue;
 
-        let count = endIndex - startIndex + 1;
+                count++;
+                elements = elements.concat(child.children);
+            }
+            return count;
+        }
 
+        let firstChild = treeElement.root ? treeElement.children[0] : treeElement;
+        let startIndex = treeOutline._indexOfTreeElement(firstChild);
+        let count = numberOfElementsInSubtree(treeElement);
         let indexes = new WI.IndexSet;
         indexes.addRange(startIndex, count);
-
         return indexes;
     }
 };