KMSearchMode.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // KMSearchMode.swift
  3. // PDF Master
  4. //
  5. // Created by lxy on 2022/12/9.
  6. //
  7. import Cocoa
  8. class KMSearchMode: NSObject {
  9. var selection : CPDFSelection = CPDFSelection()
  10. var attributedString : NSMutableAttributedString = NSMutableAttributedString()
  11. var selectionPageIndex : UInt = 0
  12. var datas : [KMSearchMode] = []
  13. var select: Bool = false
  14. var hover: Bool = false
  15. class func sortSearchResult(results:[KMSearchMode]) ->[KMSearchMode] {
  16. var sortResult : [KMSearchMode] = []
  17. var pageIndexs : [UInt] = []
  18. for mode in results {
  19. pageIndexs.append(mode.selectionPageIndex)
  20. }
  21. if Set(pageIndexs).count != pageIndexs.count {
  22. pageIndexs = Array(Set(pageIndexs))
  23. }
  24. pageIndexs = pageIndexs.sorted()
  25. for index in pageIndexs {
  26. var indexs : [KMSearchMode] = []
  27. for result in results {
  28. if result.selectionPageIndex == index {
  29. indexs.append(result)
  30. }
  31. }
  32. var s : KMSearchMode = KMSearchMode()
  33. s.datas = indexs
  34. s.selectionPageIndex = index
  35. sortResult.append(s)
  36. }
  37. return sortResult
  38. }
  39. }