Skip to content

Instantly share code, notes, and snippets.

@usagimaru
Last active April 22, 2024 17:33
Show Gist options
  • Save usagimaru/0cf7cb2c22c75493e03363f682cdaba6 to your computer and use it in GitHub Desktop.
Save usagimaru/0cf7cb2c22c75493e03363f682cdaba6 to your computer and use it in GitHub Desktop.
An extension to check if NSTextField / NSSearchField is the first responder
import Cocoa
extension NSView {
var isFirstResponder: Bool {
window?.firstResponder == self
}
}
extension NSTextField {
override var isFirstResponder: Bool {
if let fieldEditor = currentEditor() {
return fieldEditor == window?.firstResponder
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment