Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setTopBrowserView focus issue with reordering #42733

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/browser/api/browser-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ BrowserWindow.prototype.getBrowserViews = function () {

BrowserWindow.prototype.setTopBrowserView = function (browserView: BrowserView) {
if (browserView.ownerWindow !== this) { throw new Error('Given BrowserView is not attached to the window'); }
this.addBrowserView(browserView);
const idx = this._browserViews.indexOf(browserView);
if (idx >= 0) {
this.contentView.addChildView(browserView.webContentsView);
this._browserViews.splice(idx, 1);
this._browserViews.push(browserView);
}
};

module.exports = BrowserWindow;
13 changes: 13 additions & 0 deletions spec/api-browser-view-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,19 @@ describe('BrowserView module', () => {
win2.close();
win2.destroy();
});

it('should reorder the BrowserView to the top if it is already in the window', () => {
view = new BrowserView();
const view2 = new BrowserView();
defer(() => view2.webContents.destroy());
w.addBrowserView(view);
w.addBrowserView(view2);
defer(() => w.removeBrowserView(view2));

w.setTopBrowserView(view);
const views = w.getBrowserViews();
expect(views.indexOf(view)).to.equal(views.length - 1);
});
});

describe('BrowserView.webContents.getOwnerBrowserWindow()', () => {
Expand Down
Loading