// // KMSearchMode.swift // PDF Master // // Created by lxy on 2022/12/9. // import Cocoa class KMSearchMode: NSObject { var selection : CPDFSelection = CPDFSelection() var attributedString : NSMutableAttributedString = NSMutableAttributedString() var selectionPageIndex : UInt = 0 var datas : [KMSearchMode] = [] var select: Bool = false var hover: Bool = false class func sortSearchResult(results:[KMSearchMode]) ->[KMSearchMode] { var sortResult : [KMSearchMode] = [] var pageIndexs : [UInt] = [] for mode in results { pageIndexs.append(mode.selectionPageIndex) } if Set(pageIndexs).count != pageIndexs.count { pageIndexs = Array(Set(pageIndexs)) } pageIndexs = pageIndexs.sorted() for index in pageIndexs { var indexs : [KMSearchMode] = [] for result in results { if result.selectionPageIndex == index { indexs.append(result) } } var s : KMSearchMode = KMSearchMode() s.datas = indexs s.selectionPageIndex = index sortResult.append(s) } return sortResult } }