import AppKit

/// 支持 Cmd+A/C/V/X 快捷键的 NSPanel（用于独立弹窗如模型编辑器）
final class KeyEquivalentPanel: NSPanel {
    override func performKeyEquivalent(with event: NSEvent) -> Bool {
        guard event.modifierFlags.contains(.command),
              let chars = event.charactersIgnoringModifiers?.lowercased() else {
            return super.performKeyEquivalent(with: event)
        }
        let selector: Selector?
        switch chars {
        case "a": selector = #selector(NSText.selectAll(_:))
        case "c": selector = #selector(NSText.copy(_:))
        case "v": selector = #selector(NSText.paste(_:))
        case "x": selector = #selector(NSText.cut(_:))
        default:  selector = nil
        }
        guard let sel = selector else {
            return super.performKeyEquivalent(with: event)
        }
        if NSApp.sendAction(sel, to: nil, from: self) {
            return true
        }
        return super.performKeyEquivalent(with: event)
    }
}
