diff --git a/web/pgadmin/static/js/helpers/Layout.jsx b/web/pgadmin/static/js/helpers/Layout.jsx
index 8adfa6327..926904a2f 100644
--- a/web/pgadmin/static/js/helpers/Layout.jsx
+++ b/web/pgadmin/static/js/helpers/Layout.jsx
@@ -333,6 +333,7 @@ export default function Layout({groups, getLayoutInstance, layoutId, savedLayout
           groups={defaultGroups}
           onLayoutChange={(_l, currentTabId, direction)=>{
             saveLayout(layoutObj.current, layoutId);
+            direction = direction == 'update' ? 'active' : direction;
             if(Object.values(LAYOUT_EVENTS).indexOf(direction) > -1) {
               layoutEventBus.current.fireEvent(LAYOUT_EVENTS[direction.toUpperCase()], currentTabId);
             }
diff --git a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx
index 9d885c4a5..a5328ee60 100644
--- a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx
+++ b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx
@@ -318,6 +318,17 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
       eventBus.current.fireEvent(QUERY_TOOL_EVENTS.WARN_SAVE_DATA_CLOSE);
     });
 
+    panel?.on(window.wcDocker.EVENT.VISIBILITY_CHANGED, function() {
+      /* Focus the appropriate panel on visible */
+      if(panel.isVisible()) {
+        if(LayoutHelper.isTabVisible(docker.current, PANELS.QUERY)) {
+          LayoutHelper.focus(docker.current, PANELS.QUERY);
+        } else if(LayoutHelper.isTabVisible(docker.current, PANELS.HISTORY)) {
+          LayoutHelper.focus(docker.current, PANELS.HISTORY);
+        }
+      }
+    });
+
     pgAdmin.Browser.Events.on('pgadmin-storage:finish_btn:select_file', (fileName)=>{
       eventBus.current.fireEvent(QUERY_TOOL_EVENTS.LOAD_FILE, fileName);
     }, pgAdmin);
