@@ -134,26 +134,15 @@ function uxCloseBlock(blockId: string) {
134134
135135 const workspaceLayoutModel = WorkspaceLayoutModel . getInstance ( ) ;
136136 const isAIPanelOpen = workspaceLayoutModel . getAIPanelVisible ( ) ;
137-
138137 if ( isAIPanelOpen && getStaticTabBlockCount ( ) === 1 ) {
139138 const aiModel = WaveAIModel . getInstance ( ) ;
140139 const shouldSwitchToAI = ! aiModel . isChatEmpty || aiModel . hasNonEmptyInput ( ) ;
141-
142140 if ( shouldSwitchToAI ) {
143- replaceBlock (
144- blockId ,
145- {
146- meta : {
147- view : "launcher" ,
148- } ,
149- } ,
150- false
151- ) ;
141+ replaceBlock ( blockId , { meta : { view : "launcher" } } , false ) ;
152142 setTimeout ( ( ) => WaveAIModel . getInstance ( ) . focusInput ( ) , 50 ) ;
153143 return ;
154144 }
155145 }
156-
157146 const layoutModel = getLayoutModelForStaticTab ( ) ;
158147 const node = layoutModel . getNodeByBlockId ( blockId ) ;
159148 if ( node ) {
@@ -171,6 +160,22 @@ function genericClose() {
171160 TabBarModel . getInstance ( ) . jiggleActivePinnedTab ( ) ;
172161 return ;
173162 }
163+
164+ const workspaceLayoutModel = WorkspaceLayoutModel . getInstance ( ) ;
165+ const isAIPanelOpen = workspaceLayoutModel . getAIPanelVisible ( ) ;
166+ if ( isAIPanelOpen && getStaticTabBlockCount ( ) === 1 ) {
167+ const aiModel = WaveAIModel . getInstance ( ) ;
168+ const shouldSwitchToAI = ! aiModel . isChatEmpty || aiModel . hasNonEmptyInput ( ) ;
169+ if ( shouldSwitchToAI ) {
170+ const layoutModel = getLayoutModelForStaticTab ( ) ;
171+ const focusedNode = globalStore . get ( layoutModel . focusedNode ) ;
172+ if ( focusedNode ) {
173+ replaceBlock ( focusedNode . data . blockId , { meta : { view : "launcher" } } , false ) ;
174+ setTimeout ( ( ) => WaveAIModel . getInstance ( ) . focusInput ( ) , 50 ) ;
175+ return ;
176+ }
177+ }
178+ }
174179 const blockCount = getStaticTabBlockCount ( ) ;
175180 if ( blockCount === 0 ) {
176181 simpleCloseStaticTab ( ) ;
0 commit comments