Browse Source

【综合】大纲偶发crash修复

tangchao 1 year ago
parent
commit
61c8f602ee

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Outline.swift

@@ -33,7 +33,7 @@ extension KMLeftSideViewController {
             guard let tPDFOutline = self.tocOutlineView.item(atRow: i) as? CPDFOutline else {
                 continue
             }
-            let tPage = tPDFOutline.destination.page()
+            let tPage = tPDFOutline.destination?.page()
             if (tPage == nil) {
                 continue
             }

+ 18 - 2
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -1478,9 +1478,25 @@ class KMLeftSideViewController: KMSideViewController {
                 var datas: [KMBOTAAnnotationSection] = []
                 /// 根据id进行排序(升序)
                 if self.isAscendSort {
-                    allAnnotation.sort { $0.modificationDate() > $1.modificationDate() }
+                    allAnnotation.sort {
+                        if $0.modificationDate() == nil {
+                            return false
+                        }
+                        if $1.modificationDate() == nil {
+                            return false
+                        }
+                        return $0.modificationDate() > $1.modificationDate()
+                    }
                 } else {
-                    allAnnotation.sort { $0.modificationDate() <= $1.modificationDate() }
+                    allAnnotation.sort {
+                        if $0.modificationDate() == nil {
+                            return false
+                        }
+                        if $1.modificationDate() == nil {
+                            return false
+                        }
+                        return $0.modificationDate() <= $1.modificationDate()
+                    }
                 }
                 for anno in allAnnotation {
                     let section = KMBOTAAnnotationSection()

+ 16 - 25
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -2820,20 +2820,6 @@ extension KMMainViewController {
 
             pdfSplitView.setPosition(mianSplitView.maxPossiblePositionOfDivider(at: 1), ofDividerAt: 0, animate: false)
         } else {
-//            pdfSplitView.dividerStyle = .paneSplitter
-//            pdfSplitView.isVertical = !isHorizontal
-//
-//            pdfSplitView.setPosition(500, ofDividerAt: 0, animate: true)
-//
-//            if secondaryPdfView.document != nil {
-////                secondaryPdfView.frame = pdfSplitSecondView.frame
-////                pdfSplitSecondView.contentView = secondaryPdfView
-//            } else {
-//                openSecondaryPdfView = KMSecondaryViewController.init()
-//                openSecondaryPdfView?.view.frame = pdfSplitSecondView.bounds
-//                pdfSplitSecondView.contentView = openSecondaryPdfView?.view
-//                openSecondaryPdfView?.delegate = self
-//            }
             if self.newPDFSplitView.animating {
                 return
             }
@@ -2849,9 +2835,9 @@ extension KMMainViewController {
                 
                 var position = self.lastSplitPDFHeightFloat(frame)-self.lastSplitPDFHeight-Float(self.newPDFSplitView.dividerThickness)
                 var point: NSPoint = .zero
-//                PDFPage *page = nil;
+                var page: CPDFPage?
                 self.newPDFSplitView.setPosition(position.cgFloat, ofDividerAt: 0, animate: false)
-//
+
                 if (self.secondaryPdfContentView == nil) {
 //                    secondaryPdfContentView = [[SKGradientView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 200.0, 20.0)];
                     self.secondaryPdfContentView = NSView(frame: NSMakeRect(0, 0, 200, 20))
@@ -2869,10 +2855,10 @@ extension KMMainViewController {
                     self.secondaryPdfView?.setShouldAntiAlias(KMPreference.shared.antiAliasText)
                     self.secondaryPdfView?.applyDefaultInterpolationQuality()
                     self.secondaryPdfView?.setGreekingThreshold(KMPreference.shared.greekThreshold.cgFloat)
-//                    [secondaryPdfView setSynchronizeZoom:YES];
+                    self.secondaryPdfView?.setSynchronizeZoom(true)
 //        //            [secondaryPdfView setDocument:[pdfView document]];
                     point = NSMakePoint(NSMinX(frame), NSMaxY(frame) - position.cgFloat - self.newPDFSplitView.dividerThickness)
-//                    page = [pdfView pageForPoint:point nearest:YES];
+                    page = self.listView.page(for: point, nearest: true)
 //
                     let controlView = self.secondaryPdfView?.controlView
                     var color = NSColor(calibratedWhite: 0.97, alpha: 1.0)
@@ -2894,7 +2880,6 @@ extension KMMainViewController {
                     self.openSecondaryPdfView = KMSecondaryViewController()
                     self.openSecondaryPdfView?.view.frame = self.secondaryPdfContentView?.frame ?? .zero
                     self.secondaryPdfContentView?.addSubview(self.openSecondaryPdfView!.view)
-//                    __block typeof(self)weakself = self;
                     self.openSecondaryPdfView?.secondaryView.receivedFileUrlBlock = { [weak self] fileUrl in
                         if let docUrl = fileUrl {
                             _ = self?.displaySecondaryPDFView(withUrl: docUrl)
@@ -2912,15 +2897,21 @@ extension KMMainViewController {
                 }
                 
                 self.newPDFSplitView.setPosition(self.secondaryPdfContentView?.bounds.size.width ?? 120, ofDividerAt: 1, animate: false)
-//
-//                if (page) {
-//                    [secondaryPdfView goToPage:page];
+
+                if (page != nil) {
+                    self.secondaryPdfView?.go(toPageIndex: Int(page!.pageIndex()), animated: false)
 //                    point = [secondaryPdfView convertPoint:[secondaryPdfView convertPoint:[pdfView convertPoint:point toPage:page] fromPage:page] toView:[secondaryPdfView documentView]];
-//                    if ([[[secondaryPdfView scrollView] contentView] isFlipped] == NO)
-//                        point.y -= [[secondaryPdfView documentView] isFlipped] ? -NSHeight([[secondaryPdfView documentView] visibleRect]) : NSHeight([[secondaryPdfView documentView] visibleRect]);
+                    let tmpP = self.listView.convert(point, to: page)
+                    let conP = self.secondaryPdfView?.convert(tmpP, from: page) ?? .zero
+                    point = self.secondaryPdfView?.convert(conP, to: self.secondaryPdfView?.documentView()) ?? .zero
+                    if let docView = self.secondaryPdfView?.documentView(), docView.contentView.isFlipped == false {
+//                        point.y -= docView.isFlipped ? NSHeight(docView.visibleRect) : nshei
+                        //                        point.y -= [[secondaryPdfView documentView] isFlipped] ? -NSHeight([[secondaryPdfView documentView] visibleRect]) : NSHeight([[secondaryPdfView documentView] visibleRect]);
+                        
+                    }
 //                    [[secondaryPdfView documentView] scrollPoint:point];
 //                    [secondaryPdfView layoutDocumentView];
-//                }
+                }
             }
 //            [[self window] recalculateKeyViewLoop];
 //            if ([self interactionMode] == SKLegacyFullScreenMode)