Web Inspector: Unfocusing / Focusing inspector window should not change ContentView
authormattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Sep 2016 17:25:38 +0000 (17:25 +0000)
committermattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Sep 2016 17:25:38 +0000 (17:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=162572
<rdar://problem/28479562>

Reviewed by Brian Burg.

Improve NavigationSidebarPanel logic for coordinating selection between trees.
When tree selection changes, the most recent selection should be restored
the next time the tree is focused.

The sidebar should also handle focusing a tree for the first time, in
which no previous selection exists, and focusing a tree that has had its
previous selection filtered out (hidden).

* UserInterface/Views/NavigationSidebarPanel.js:
(WebInspector.NavigationSidebarPanel.prototype._contentTreeOutlineDidFocus):
(WebInspector.NavigationSidebarPanel.prototype._contentTreeOutlineTreeSelectionDidChange):
Restoring the last deselected element, instead of the last selected element
only works when the selection is moving from one tree to another. When
the elements belong to the same tree the newly selected element won't
be saved until the next selection change. If the window loses and regains
the focus before then, the tree will restore the previous selection,
effectively reverting the last selection change.

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

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

index b895def..f8f376a 100644 (file)
@@ -1,3 +1,29 @@
+2016-09-27  Matt Baker  <mattbaker@apple.com>
+
+        Web Inspector: Unfocusing / Focusing inspector window should not change ContentView
+        https://bugs.webkit.org/show_bug.cgi?id=162572
+        <rdar://problem/28479562>
+
+        Reviewed by Brian Burg.
+
+        Improve NavigationSidebarPanel logic for coordinating selection between trees.
+        When tree selection changes, the most recent selection should be restored
+        the next time the tree is focused.
+
+        The sidebar should also handle focusing a tree for the first time, in
+        which no previous selection exists, and focusing a tree that has had its
+        previous selection filtered out (hidden).
+
+        * UserInterface/Views/NavigationSidebarPanel.js:
+        (WebInspector.NavigationSidebarPanel.prototype._contentTreeOutlineDidFocus):
+        (WebInspector.NavigationSidebarPanel.prototype._contentTreeOutlineTreeSelectionDidChange):
+        Restoring the last deselected element, instead of the last selected element
+        only works when the selection is moving from one tree to another. When
+        the elements belong to the same tree the newly selected element won't
+        be saved until the next selection change. If the window loses and regains
+        the focus before then, the tree will restore the previous selection,
+        effectively reverting the last selection change.
+
 2016-09-27  Tomas Popela  <tpopela@redhat.com>
 
         [GTK] Mac defaults are used for key shortcuts on Linux
index 554cfaf..e8baf09 100644 (file)
@@ -647,6 +647,15 @@ WebInspector.NavigationSidebarPanel = class NavigationSidebarPanel extends WebIn
             return;
 
         let previousSelectedTreeElement = treeOutline[WebInspector.NavigationSidebarPanel.PreviousSelectedTreeElementSymbol];
+        if (!previousSelectedTreeElement || previousSelectedTreeElement.hidden) {
+            const skipUnrevealed = true;
+            let firstVisibleTreeElement = treeOutline.children[0];
+            while (firstVisibleTreeElement && firstVisibleTreeElement.hidden)
+                firstVisibleTreeElement = firstVisibleTreeElement.traverseNextTreeElement(skipUnrevealed, this);
+
+            previousSelectedTreeElement = firstVisibleTreeElement;
+        }
+
         if (!previousSelectedTreeElement)
             return;
 
@@ -655,15 +664,14 @@ WebInspector.NavigationSidebarPanel = class NavigationSidebarPanel extends WebIn
 
     _contentTreeOutlineTreeSelectionDidChange(event)
     {
-        let {selectedElement, deselectedElement} = event.data;
-        if (deselectedElement)
-            deselectedElement.treeOutline[WebInspector.NavigationSidebarPanel.PreviousSelectedTreeElementSymbol] = deselectedElement;
-
+        let selectedElement = event.data.selectedElement;
         if (!selectedElement)
             return;
 
-        // Prevent two selections in the sidebar.
         let selectedTreeOutline = selectedElement.treeOutline;
+        selectedTreeOutline[WebInspector.NavigationSidebarPanel.PreviousSelectedTreeElementSymbol] = selectedElement;
+
+        // Prevent multiple selections in the sidebar.
         for (let treeOutline of this._visibleContentTreeOutlines) {
             if (selectedTreeOutline === treeOutline)
                 continue;