浏览代码

Fix pdf search

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 年之前
父节点
当前提交
b5c6320ac4
共有 2 个文件被更改,包括 31 次插入16 次删除
  1. 2 2
      Nextcloud.xcodeproj/project.pbxproj
  2. 29 14
      iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift

+ 2 - 2
Nextcloud.xcodeproj/project.pbxproj

@@ -3006,7 +3006,7 @@
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 10;
+				CURRENT_PROJECT_VERSION = 11;
 				DEVELOPMENT_TEAM = 6JLRKY9ZV7;
 				ENABLE_BITCODE = NO;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -3067,7 +3067,7 @@
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 10;
+				CURRENT_PROJECT_VERSION = 11;
 				DEVELOPMENT_TEAM = 6JLRKY9ZV7;
 				ENABLE_BITCODE = NO;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;

+ 29 - 14
iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift

@@ -474,6 +474,8 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
 
     func searchPdfSelection(_ pdfSelection: PDFSelection) {
 
+        removeAllAnnotations()
+        
         pdfSelection.pages.forEach { page in
             let highlight = PDFAnnotation(bounds: pdfSelection.bounds(for: page), forType: .highlight, withProperties: nil)
             highlight.endLineStyle = .square
@@ -490,20 +492,33 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
 
         guard let pdf = pdfView.document else { return }
 
-         if let pageNr = Int(label) {
-             if pageNr > 0 && pageNr <= pdf.pageCount {
-                 if let page = pdf.page(at: pageNr - 1) {
-                     self.pdfView.go(to: page)
-                 }
-             } else {
-                 let alertController = UIAlertController(title: NSLocalizedString("_invalid_page_", comment: ""),
-                                                         message: NSLocalizedString("_the_entered_page_number_doesn't_exist_", comment: ""),
-                                                         preferredStyle: .alert)
-                 alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: nil))
-                 self.present(alertController, animated: true, completion: nil)
-             }
-         }
-     }
+        if let pageNr = Int(label) {
+            if pageNr > 0 && pageNr <= pdf.pageCount {
+                if let page = pdf.page(at: pageNr - 1) {
+                    self.pdfView.go(to: page)
+                }
+            } else {
+                let alertController = UIAlertController(title: NSLocalizedString("_invalid_page_", comment: ""),
+                                                        message: NSLocalizedString("_the_entered_page_number_doesn't_exist_", comment: ""),
+                                                        preferredStyle: .alert)
+                alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: nil))
+                self.present(alertController, animated: true, completion: nil)
+            }
+        }
+    }
+
+    func removeAllAnnotations() {
+        guard let document = pdfDocument else { return }
+
+        for i in 0..<document.pageCount {
+            if let page = document.page(at: i) {
+                let annotations = page.annotations
+                for annotation in annotations {
+                    page.removeAnnotation(annotation)
+                }
+            }
+        }
+    }
 }
 
 extension NCViewerPDF: UIGestureRecognizerDelegate {