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: Correct modal focus behavior on macOS #18995

Merged
merged 8 commits into from Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions shell/browser/ui/cocoa/atom_ns_window_delegate.mm
Expand Up @@ -88,11 +88,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
38 changes: 38 additions & 0 deletions spec/api-browser-window-spec.js
Expand Up @@ -1637,6 +1637,44 @@ describe('BrowserWindow module', () => {
})
})

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

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

// after child gains focus, attempt to focus on
// main window, and set flag if this was successful
child.once('focus', () => {
w.once('focus', () => {
hasMainFocusAfterModalFocus = true
})
w.focus()
// close child to end the spec
child.close()
})

// clean up and assert that main window never
// regained focus
child.once('closed', () => {
codebytere marked this conversation as resolved.
Show resolved Hide resolved
w.removeAllListeners()
w.close()
expect(hasMainFocusAfterModalFocus).to.equal(false)
done()
})

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

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

Expand Down