//
//  KMLeftSideViewSearchField.swift
//  PDF Reader Pro
//
//  Created by tangchao on 2023/11/15.
//

import Cocoa

class KMLeftSideViewSearchField: NSSearchField {
    var changeCallBack: ((_ changeContent: String?) -> Void)?
    var endEditCallBack: ((_ isEndEdit: Bool)->Void)?
    
    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)

        // Drawing code here.
    }
    
    override func textDidChange(_ notification: Notification) {
        super.textDidChange(notification)
        
        let searchField = notification.object as? NSTextView
        if (self.changeCallBack != nil) {
            self.changeCallBack?(searchField?.string)
        }
    }
    
    override func textDidEndEditing(_ notification: Notification) {
        super.textDidEndEditing(notification)
        
        guard let callback = self.endEditCallBack else {
            return
        }
        callback(true)
    }
}