fix: setTopBrowserView focus issue with reordering (#42733)
* fix: reorder top browser view instead of adding/removing Co-authored-by: Alice Zhao <alice@makenotion.com> * fix: update browserViews order Co-authored-by: Alice Zhao <alice@makenotion.com> * test: add a test for setTopBrowserView Co-authored-by: Alice Zhao <alice@makenotion.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Alice Zhao <alice@makenotion.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
parent
44ecf4a9e0
commit
de6e6b60bc
2 changed files with 19 additions and 1 deletions
|
@ -232,7 +232,12 @@ BrowserWindow.prototype.getBrowserViews = function () {
|
||||||
|
|
||||||
BrowserWindow.prototype.setTopBrowserView = function (browserView: BrowserView) {
|
BrowserWindow.prototype.setTopBrowserView = function (browserView: BrowserView) {
|
||||||
if (browserView.ownerWindow !== this) { throw new Error('Given BrowserView is not attached to the window'); }
|
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;
|
module.exports = BrowserWindow;
|
||||||
|
|
|
@ -520,6 +520,19 @@ describe('BrowserView module', () => {
|
||||||
win2.close();
|
win2.close();
|
||||||
win2.destroy();
|
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()', () => {
|
describe('BrowserView.webContents.getOwnerBrowserWindow()', () => {
|
||||||
|
|
Loading…
Reference in a new issue