Skip to content

Commit db8e52b

Browse files
authored
Merge branch 'master' into fix/titlebar-maximize-focus
2 parents 6253eec + 66d31c3 commit db8e52b

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

src/main/sessionwindow/sessionwindow.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export class SessionWindow implements IDisposable {
182182
});
183183
this._window.on('blur', () => {
184184
titleBarView.deactivate();
185+
this._hideEnvSelectPopup();
185186
});
186187

187188
titleBarView.load();
@@ -1367,18 +1368,23 @@ export class SessionWindow implements IDisposable {
13671368
}
13681369

13691370
const titleBarRect = this._titleBarView.view.getBounds();
1370-
const popupWidth = 600;
13711371
const paddingRight = process.platform === 'darwin' ? 33 : 127;
1372+
// Anchor the popup's right edge near the env button and cap its width to
1373+
// what fits, so on a narrow window it shrinks (the popup content is
1374+
// responsive) instead of hanging off an edge with the search box or the
1375+
// env list clipped.
1376+
const rightEdge = titleBarRect.width - paddingRight;
1377+
const popupWidth = Math.min(600, rightEdge);
13721378
// shorten browser view height if larger than max allowed
13731379
const maxHeight = Math.min(
13741380
this._envSelectPopup.getScrollHeight(),
13751381
defaultEnvSelectPopupHeight
13761382
);
13771383

13781384
this._envSelectPopup.view.view.setBounds({
1379-
x: Math.round(titleBarRect.width - paddingRight - popupWidth),
1385+
x: Math.round(rightEdge - popupWidth),
13801386
y: Math.round(titleBarRect.height),
1381-
width: popupWidth,
1387+
width: Math.round(popupWidth),
13821388
height: Math.round(maxHeight)
13831389
});
13841390
}

test/unit/sessionwindow-dispose.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,32 @@ describe('SessionWindow._disposeSession', () => {
2323
await expect(win._disposeSession()).resolves.toBeUndefined();
2424
});
2525
});
26+
27+
describe('SessionWindow._resizeEnvSelectPopup', () => {
28+
it('keeps the popup on screen when the window is narrower than the popup', () => {
29+
// Arrange: a 400px title bar (the window minWidth) is narrower than the
30+
// 600px popup, so an unclamped x would place the popup off the left edge.
31+
const setBounds = vi.fn();
32+
const win = makeWindow({
33+
_envSelectPopupVisible: true,
34+
_titleBarView: {
35+
view: { getBounds: () => ({ width: 400, height: 60 }) }
36+
},
37+
_envSelectPopup: {
38+
getScrollHeight: () => 300,
39+
view: { view: { setBounds } }
40+
}
41+
});
42+
43+
// Act
44+
win._resizeEnvSelectPopup();
45+
46+
// Assert: the whole popup fits inside the window, so neither the search box
47+
// on the left nor the env list on the right is clipped. Clamping x alone
48+
// would only move the clipping to the other edge, so the width is capped too.
49+
expect(setBounds).toHaveBeenCalledTimes(1);
50+
const bounds = setBounds.mock.calls[0][0];
51+
expect(bounds.x).toBeGreaterThanOrEqual(0);
52+
expect(bounds.x + bounds.width).toBeLessThanOrEqual(400);
53+
});
54+
});

0 commit comments

Comments
 (0)