@@ -183,6 +183,7 @@ export class SessionWindow implements IDisposable {
183183 } ) ;
184184 this . _window . on ( 'blur' , ( ) => {
185185 titleBarView . deactivate ( ) ;
186+ this . _hideEnvSelectPopup ( ) ;
186187 } ) ;
187188
188189 titleBarView . load ( ) ;
@@ -193,10 +194,16 @@ export class SessionWindow implements IDisposable {
193194 // this._labView freshly means an env switch that recreates the labView cannot
194195 // leave a stale, disposed webContents behind, nor accumulate a handler per switch.
195196 this . _window . webContents . on ( 'focus' , ( ) => {
196- this . _labView ?. view ?. webContents ?. focus ( ) ;
197+ const wc = this . contentView ?. webContents ;
198+ if ( wc && ! wc . isDestroyed ( ) ) {
199+ wc . focus ( ) ;
200+ }
197201 } ) ;
198202 this . _titleBarView . view . webContents . on ( 'focus' , ( ) => {
199- this . _labView ?. view ?. webContents ?. focus ( ) ;
203+ const wc = this . contentView ?. webContents ;
204+ if ( wc && ! wc . isDestroyed ( ) ) {
205+ wc . focus ( ) ;
206+ }
200207 } ) ;
201208
202209 if ( this . _contentViewType === ContentViewType . Lab ) {
@@ -241,12 +248,15 @@ export class SessionWindow implements IDisposable {
241248 this . _resizeViewsDelayed ( ) ;
242249 } ) ;
243250 this . _window . on ( 'maximize' , ( ) => {
251+ this . _titleBarView . setMaximized ( this . _window . isMaximized ( ) ) ;
244252 this . _resizeViewsDelayed ( ) ;
245253 } ) ;
246254 this . _window . on ( 'unmaximize' , ( ) => {
255+ this . _titleBarView . setMaximized ( this . _window . isMaximized ( ) ) ;
247256 this . _resizeViewsDelayed ( ) ;
248257 } ) ;
249258 this . _window . on ( 'restore' , ( ) => {
259+ this . _titleBarView . setMaximized ( this . _window . isMaximized ( ) ) ;
250260 this . _resizeViewsDelayed ( ) ;
251261 } ) ;
252262 this . _window . on ( 'move' , ( ) => {
@@ -375,7 +385,9 @@ export class SessionWindow implements IDisposable {
375385 this . _window . contentView . addChildView ( labView . view ) ;
376386
377387 labView . view . webContents . on ( 'did-finish-load' , ( ) => {
378- labView . view . webContents . focus ( ) ;
388+ if ( this . _window . isFocused ( ) ) {
389+ labView . view . webContents . focus ( ) ;
390+ }
379391 } ) ;
380392
381393 labView . load ( ( errorCode : number , errorDescription : string ) => {
@@ -1382,18 +1394,23 @@ export class SessionWindow implements IDisposable {
13821394 }
13831395
13841396 const titleBarRect = this . _titleBarView . view . getBounds ( ) ;
1385- const popupWidth = 600 ;
13861397 const paddingRight = process . platform === 'darwin' ? 33 : 127 ;
1398+ // Anchor the popup's right edge near the env button and cap its width to
1399+ // what fits, so on a narrow window it shrinks (the popup content is
1400+ // responsive) instead of hanging off an edge with the search box or the
1401+ // env list clipped.
1402+ const rightEdge = titleBarRect . width - paddingRight ;
1403+ const popupWidth = Math . min ( 600 , rightEdge ) ;
13871404 // shorten browser view height if larger than max allowed
13881405 const maxHeight = Math . min (
13891406 this . _envSelectPopup . getScrollHeight ( ) ,
13901407 defaultEnvSelectPopupHeight
13911408 ) ;
13921409
13931410 this . _envSelectPopup . view . view . setBounds ( {
1394- x : Math . round ( titleBarRect . width - paddingRight - popupWidth ) ,
1411+ x : Math . round ( rightEdge - popupWidth ) ,
13951412 y : Math . round ( titleBarRect . height ) ,
1396- width : popupWidth ,
1413+ width : Math . round ( popupWidth ) ,
13971414 height : Math . round ( maxHeight )
13981415 } ) ;
13991416 }
0 commit comments