@@ -177,6 +177,7 @@ export class SessionWindow implements IDisposable {
177177 } ) ;
178178 this . _window . on ( 'blur' , ( ) => {
179179 titleBarView . deactivate ( ) ;
180+ this . _hideEnvSelectPopup ( ) ;
180181 } ) ;
181182
182183 titleBarView . load ( ) ;
@@ -187,10 +188,16 @@ export class SessionWindow implements IDisposable {
187188 // this._labView freshly means an env switch that recreates the labView cannot
188189 // leave a stale, disposed webContents behind, nor accumulate a handler per switch.
189190 this . _window . webContents . on ( 'focus' , ( ) => {
190- this . _labView ?. view ?. webContents ?. focus ( ) ;
191+ const wc = this . contentView ?. webContents ;
192+ if ( wc && ! wc . isDestroyed ( ) ) {
193+ wc . focus ( ) ;
194+ }
191195 } ) ;
192196 this . _titleBarView . view . webContents . on ( 'focus' , ( ) => {
193- this . _labView ?. view ?. webContents ?. focus ( ) ;
197+ const wc = this . contentView ?. webContents ;
198+ if ( wc && ! wc . isDestroyed ( ) ) {
199+ wc . focus ( ) ;
200+ }
194201 } ) ;
195202
196203 if ( this . _contentViewType === ContentViewType . Lab ) {
@@ -235,12 +242,15 @@ export class SessionWindow implements IDisposable {
235242 this . _resizeViewsDelayed ( ) ;
236243 } ) ;
237244 this . _window . on ( 'maximize' , ( ) => {
245+ this . _titleBarView . setMaximized ( this . _window . isMaximized ( ) ) ;
238246 this . _resizeViewsDelayed ( ) ;
239247 } ) ;
240248 this . _window . on ( 'unmaximize' , ( ) => {
249+ this . _titleBarView . setMaximized ( this . _window . isMaximized ( ) ) ;
241250 this . _resizeViewsDelayed ( ) ;
242251 } ) ;
243252 this . _window . on ( 'restore' , ( ) => {
253+ this . _titleBarView . setMaximized ( this . _window . isMaximized ( ) ) ;
244254 this . _resizeViewsDelayed ( ) ;
245255 } ) ;
246256 this . _window . on ( 'move' , ( ) => {
@@ -373,7 +383,9 @@ export class SessionWindow implements IDisposable {
373383 this . _window . contentView . addChildView ( labView . view ) ;
374384
375385 labView . view . webContents . on ( 'did-finish-load' , ( ) => {
376- labView . view . webContents . focus ( ) ;
386+ if ( this . _window . isFocused ( ) ) {
387+ labView . view . webContents . focus ( ) ;
388+ }
377389 } ) ;
378390
379391 labView . load ( ( errorCode : number , errorDescription : string ) => {
@@ -1363,18 +1375,23 @@ export class SessionWindow implements IDisposable {
13631375 }
13641376
13651377 const titleBarRect = this . _titleBarView . view . getBounds ( ) ;
1366- const popupWidth = 600 ;
13671378 const paddingRight = process . platform === 'darwin' ? 33 : 127 ;
1379+ // Anchor the popup's right edge near the env button and cap its width to
1380+ // what fits, so on a narrow window it shrinks (the popup content is
1381+ // responsive) instead of hanging off an edge with the search box or the
1382+ // env list clipped.
1383+ const rightEdge = titleBarRect . width - paddingRight ;
1384+ const popupWidth = Math . min ( 600 , rightEdge ) ;
13681385 // shorten browser view height if larger than max allowed
13691386 const maxHeight = Math . min (
13701387 this . _envSelectPopup . getScrollHeight ( ) ,
13711388 defaultEnvSelectPopupHeight
13721389 ) ;
13731390
13741391 this . _envSelectPopup . view . view . setBounds ( {
1375- x : Math . round ( titleBarRect . width - paddingRight - popupWidth ) ,
1392+ x : Math . round ( rightEdge - popupWidth ) ,
13761393 y : Math . round ( titleBarRect . height ) ,
1377- width : popupWidth ,
1394+ width : Math . round ( popupWidth ) ,
13781395 height : Math . round ( maxHeight )
13791396 } ) ;
13801397 }
0 commit comments