import AppKit

// MARK: - Cmd+A/C/V/X 安全输入框

final class KeyEquivalentSecureTextField: NSSecureTextField {
    override func performKeyEquivalent(with event: NSEvent) -> Bool {
        guard event.modifierFlags.contains(.command),
              let chars = event.charactersIgnoringModifiers?.lowercased() else {
            return super.performKeyEquivalent(with: event)
        }
        switch chars {
        case "a": return NSApp.sendAction(#selector(NSText.selectAll(_:)), to: currentEditor() ?? self, from: self)
        case "c": return NSApp.sendAction(#selector(NSText.copy(_:)), to: currentEditor() ?? self, from: self)
        case "v": return NSApp.sendAction(#selector(NSText.paste(_:)), to: currentEditor() ?? self, from: self)
        case "x": return NSApp.sendAction(#selector(NSText.cut(_:)), to: currentEditor() ?? self, from: self)
        default:  return super.performKeyEquivalent(with: event)
        }
    }
}
