|
@@ -9,6 +9,73 @@ import Foundation
|
|
|
|
|
|
extension KMMainViewController {
|
|
|
func search(searchString: String, isCase: Bool, display: Bool = true, needShowAll: Bool = false) {
|
|
|
+ let isEditing = self.listView?.isEditing() ?? false
|
|
|
+ if isEditing {
|
|
|
+ if searchString.isEmpty {
|
|
|
+ self.listView.setHighlightedSelection(nil, animated: false)
|
|
|
+ self.leftSideViewController.searchResults = []
|
|
|
+
|
|
|
+ if display {
|
|
|
+ if self.leftSideViewController.findPaneState == .singular {
|
|
|
+ self.leftSideViewController.displayFindViewAnimating(true)
|
|
|
+ } else {
|
|
|
+ self.leftSideViewController.displayGroupedFindViewAnimating(true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let isWholeWord = self.leftSideViewController.mwcFlags.wholeWordSearch == 1
|
|
|
+// self.srHanddler.newSearch(keyword: searchString, isCase: isCase, isWholeWord: isWholeWord) { models in
|
|
|
+// KMPrint("")
|
|
|
+// }
|
|
|
+ var opt = CPDFSearchOptions()
|
|
|
+ if isCase == false {
|
|
|
+ opt.insert(.caseSensitive)
|
|
|
+ }
|
|
|
+ if isWholeWord {
|
|
|
+ opt.insert(.matchWholeWord)
|
|
|
+ }
|
|
|
+
|
|
|
+ let datas = self.srHanddler.pdfView?.document.findEditAllPageString(searchString, with: opt) ?? []
|
|
|
+ if let sel = datas.first?.first {
|
|
|
+ self.srHanddler.showSelection(sel)
|
|
|
+ }
|
|
|
+
|
|
|
+ self.searchResults.removeAll()
|
|
|
+ var _selections: [CPDFSelection] = []
|
|
|
+ for selections in datas {
|
|
|
+ for selection in selections {
|
|
|
+ let mode : KMSearchMode = KMSearchMode()
|
|
|
+ mode.selection = selection
|
|
|
+ mode.attributedString = KMOCToolClass.getAttributedString(selection: selection, keyword: searchString)
|
|
|
+ mode.selectionPageIndex = self.listView.document.index(for: selection.page)
|
|
|
+ self.searchResults.insert(mode, at: self.searchResults.count)
|
|
|
+ _selections.append(selection)
|
|
|
+ selection.setColor(NSColor(red: 236/255.0, green: 241/255.0, blue: 83/255.0, alpha: 0.5))
|
|
|
+// self.listView.setHighlight(selection, forBorderColor: .yellow, fill: .red, animated: false)
|
|
|
+ }
|
|
|
+// self.listView.setHighlightedSelections(selections )
|
|
|
+ }
|
|
|
+
|
|
|
+ if needShowAll {
|
|
|
+ self.listView.setHighlightedSelections(_selections)
|
|
|
+ }
|
|
|
+ if _selections.isEmpty {
|
|
|
+ self.listView.setHighlightedSelection(nil, animated: false)
|
|
|
+ }
|
|
|
+ self.listView.setNeedsDisplayAnnotationViewForVisiblePages()
|
|
|
+ self.leftSideViewController.searchResults = self.searchResults
|
|
|
+
|
|
|
+ if display {
|
|
|
+ if self.leftSideViewController.findPaneState == .singular {
|
|
|
+ self.leftSideViewController.displayFindViewAnimating(true)
|
|
|
+ } else {
|
|
|
+ self.leftSideViewController.displayGroupedFindViewAnimating(true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
let document = self.listView.document
|
|
|
if let data = document?.isFinding, data {
|
|
|
document?.cancelFindString()
|