FocusAwareSecureTextField.swift 626 B

12345678910111213141516171819202122232425
  1. //
  2. // FocusAwareSecureTextField.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by lizhe on 2023/10/23.
  6. //
  7. import Cocoa
  8. class FocusAwareSecureTextField: NSSecureTextField {
  9. var onFocus: () -> Void = {}
  10. var onUnfocus: () -> Void = {}
  11. override func becomeFirstResponder() -> Bool {
  12. onFocus()
  13. let textView = window?.fieldEditor(true, for: nil) as? NSTextView
  14. textView?.insertionPointColor = NSColor.km_init(hex: "#252629")
  15. return super.becomeFirstResponder()
  16. }
  17. override func resignFirstResponder() -> Bool {
  18. onUnfocus()
  19. return super.resignFirstResponder()
  20. }
  21. }