Web Inspector: the Dock Side navigation item is automatically focused when Web Inspec...
authornvasilyev@apple.com <nvasilyev@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Mar 2020 03:32:05 +0000 (03:32 +0000)
committernvasilyev@apple.com <nvasilyev@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Mar 2020 03:32:05 +0000 (03:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=209760

Reviewed by Devin Rousso.

When undocking, Web Inspector focuses on the first visible focusable element. I don't know why.
This patch restores the focus to the previously focused element.

* UserInterface/Base/Main.js:

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Main.js

index 787fe19..ca70d5e 100644 (file)
@@ -1,3 +1,15 @@
+2020-03-30  Nikita Vasilyev  <nvasilyev@apple.com>
+
+        Web Inspector: the Dock Side navigation item is automatically focused when Web Inspector is opened detached, preventing any global spacebar shortcuts from working
+        https://bugs.webkit.org/show_bug.cgi?id=209760
+
+        Reviewed by Devin Rousso.
+
+        When undocking, Web Inspector focuses on the first visible focusable element. I don't know why.
+        This patch restores the focus to the previously focused element.
+
+        * UserInterface/Base/Main.js:
+
 2020-03-30  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: REGRESSION(r259101): items in the contextmenu of the tab bar don't have any text
index b6ee80e..300869c 100644 (file)
@@ -901,6 +901,19 @@ WI.updateDockedState = function(side)
 
     if (!WI.dockedConfigurationSupportsSplitContentBrowser() && !WI.doesCurrentTabSupportSplitContentBrowser())
         WI.hideSplitConsole();
+
+    if (side === WI.DockConfiguration.Undocked && WI.Platform.name === "mac") {
+        // When undocking, the first visible focusable element steals focus. Undo this.
+        document.body.addEventListener("focusin", function(event) {
+            let firstFocusableElement = document.querySelector("[tabindex='0']:not(.hidden)");
+            if (firstFocusableElement === event.target) {
+                if (WI.previousFocusElement)
+                    WI.previousFocusElement.focus();
+                else
+                    event.target.blur();
+            }
+        }, {once: true, capture: true});
+    }
 };
 
 WI.resizeDockedFrameMouseDown = function(event)