From fea7f403b3537c2b2fede9275ff77a0661a92712 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 9 Apr 2026 16:36:49 -0400 Subject: [PATCH] Fix "Try Now" button opening git panel instead of agent panel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a user on editor layout clicks "Try Now" on the parallel agents announcement, the callback dispatches ToggleFocus in the same flush cycle as set_layout(Agent). Because set_layout writes to the settings file asynchronously, ToggleFocus opens the agent panel in its old dock (right dock in editor layout). When the settings later reload, per-panel migration observers fire in registration order. If the git panel migrates to the right dock before the agent panel migrates out, the git panel takes the active slot, and the agent panel's was_visible flag becomes false when it subsequently moves to the left dock—leaving the git panel visible and the agent panel hidden. Fix: when switching layouts, defer the ToggleFocus dispatch until after the settings change propagates by using a one-shot observe_global observer on SettingsStore. Global observers fire in registration order, so by the time this observer runs, all panel-migration observers (registered at workspace creation) have already moved every panel to its correct position. --- Cargo.lock | 1 + crates/auto_update_ui/Cargo.toml | 1 + crates/auto_update_ui/src/auto_update_ui.rs | 45 ++++++++++++++++++--- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67495074258f02a658b5b95eb9b8e6625d6cbeb0..c583b1b15c8dadbd6429bac1504cf402b1f0c3ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1252,6 +1252,7 @@ dependencies = [ "semver", "serde", "serde_json", + "settings", "smol", "telemetry", "ui", diff --git a/crates/auto_update_ui/Cargo.toml b/crates/auto_update_ui/Cargo.toml index b7b51c4a28448434ec4483f898e2d67b3301533e..d9526292d3ddaf352fcaa029105bf035b2bc920e 100644 --- a/crates/auto_update_ui/Cargo.toml +++ b/crates/auto_update_ui/Cargo.toml @@ -24,6 +24,7 @@ markdown_preview.workspace = true release_channel.workspace = true semver.workspace = true serde.workspace = true +settings.workspace = true serde_json.workspace = true smol.workspace = true telemetry.workspace = true diff --git a/crates/auto_update_ui/src/auto_update_ui.rs b/crates/auto_update_ui/src/auto_update_ui.rs index 6773dea5a09ad3bbe1a43761b6df43a56e195d8d..a3facec5d82498de3a412ddb24c9ddaf1dc031d4 100644 --- a/crates/auto_update_ui/src/auto_update_ui.rs +++ b/crates/auto_update_ui/src/auto_update_ui.rs @@ -1,3 +1,5 @@ +use std::cell::RefCell; +use std::rc::Rc; use std::sync::Arc; use agent_settings::{AgentSettings, WindowLayout}; @@ -6,12 +8,14 @@ use db::kvp::Dismissable; use editor::{Editor, MultiBuffer}; use fs::Fs; use gpui::{ - App, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Window, actions, prelude::*, + App, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Subscription, Window, actions, + prelude::*, }; use markdown_preview::markdown_preview_view::{MarkdownPreviewMode, MarkdownPreviewView}; use release_channel::{AppVersion, ReleaseChannel}; use semver::Version; use serde::Deserialize; +use settings::SettingsStore; use smol::io::AsyncReadExt; use ui::{AnnouncementToast, ListBulletItem, ParallelAgentsIllustration, prelude::*}; use util::{ResultExt as _, maybe}; @@ -207,12 +211,43 @@ fn announcement_for_version(version: &Version, cx: &App) -> Option)); + let subscription_ref = subscription.clone(); + *subscription.borrow_mut() = + Some(cx.observe_global::(move |cx| { + if matches!( + AgentSettings::get_layout(cx), + WindowLayout::Agent(_) + ) { + cx.update_window(window_handle, |_, window, cx| { + window.dispatch_action( + Box::new(zed_actions::assistant::ToggleFocus), + cx, + ); + }) + .ok(); + subscription_ref.borrow_mut().take(); + } + })); + } })), on_dismiss: Some(Arc::new(|cx| { ParallelAgentAnnouncement::set_dismissed(true, cx)