Skip to content

Commit

Permalink
fix: Correct modal focus behavior on macOS (#19061)
Browse files Browse the repository at this point in the history
* wip: wish i could hack the main window focus away

* main -> key

* remove useless code

* test: Add focus event spec

* test: more robust spec

* test: simplify test

* duplicate non-firing macOS event listener 😳

* destroy 🚨

* chore: remove unused variable
  • Loading branch information
trop[bot] authored and codebytere committed Jul 3, 2019
1 parent b98e06e commit b9605cc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions atom/browser/ui/cocoa/atom_ns_window_delegate.mm
Expand Up @@ -83,11 +83,11 @@ - (NSRect)windowWillUseStandardFrame:(NSWindow*)window
return frame;
}

- (void)windowDidBecomeMain:(NSNotification*)notification {
- (void)windowDidBecomeKey:(NSNotification*)notification {
shell_->NotifyWindowFocus();
}

- (void)windowDidResignMain:(NSNotification*)notification {
- (void)windowDidResignKey:(NSNotification*)notification {
shell_->NotifyWindowBlur();
}

Expand Down
27 changes: 27 additions & 0 deletions spec/api-browser-window-spec.js
Expand Up @@ -2330,6 +2330,33 @@ describe('BrowserWindow module', () => {
})
})

describe('focus event', () => {
it('should not emit if focusing on a main window with a modal open', (done) => {
const child = new BrowserWindow({
parent: w,
modal: true,
show: false
})

child.once('ready-to-show', () => {
child.show()
})

child.on('show', () => {
w.once('focus', () => {
expect(child.isDestroyed()).to.equal(true)
done()
})
w.focus() // this should not trigger the above listener
child.close()
})

// act
child.loadURL(server.url)
w.show()
})
})

describe('sheet-begin event', () => {
let sheet = null

Expand Down

0 comments on commit b9605cc

Please sign in to comment.