Browse Source

【APPCenter】编号:V4.0.1.37

lizhe 9 months ago
parent
commit
b66587c20a

+ 32 - 7
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Event.m

@@ -1136,27 +1136,52 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
 #pragma mark - ToolMode
 
 - (BOOL)doDragTextWithEvent:(NSEvent *)theEvent {
-    if (![self currentSelection])
+    // 检查当前是否有选中内容
+    if (![self currentSelection]) {
         return NO;
+    }
     
     NSPoint point;
+    // 获取事件对应的页码和位置点
     CPDFPage *page = [self pageAndPoint:&point forEvent:theEvent nearest:NO];
     
+    // 验证页码和位置点是否有效,并且是否允许拖拽
     if (page == nil ||
-        NSPointInRect(point, [[self currentSelection] boundsForPage:page]) == NO ||
-        [CPDFListView willDragMouse] == NO)
+        !NSPointInRect(point, [[self currentSelection] boundsForPage:page]) ||
+        ![CPDFListView willDragMouse]) {
         return NO;
+    }
     
+    // 创建拖拽使用的粘贴板
     NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSPasteboardNameDrag];
-    NSImage *dragImage = [NSImage bitmapPDFListViewImageWithSize:NSMakeSize(32.0, 32.0) scale:[self backingScale] drawingHandler:^(NSRect rect){
-        [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kClippingTextType)] drawInRect:rect fromRect:rect operation:NSCompositingOperationCopy fraction:0.9 respectFlipped:YES hints:nil];
+    
+    // 创建拖拽图像
+    NSImage *dragImage = [NSImage bitmapPDFListViewImageWithSize:NSMakeSize(32.0, 32.0)
+                                                           scale:[self backingScale]
+                                                 drawingHandler:^(NSRect rect) {
+        [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kClippingTextType)]
+            drawInRect:rect
+            fromRect:NSZeroRect
+            operation:NSCompositingOperationCopy
+            fraction:0.9
+            respectFlipped:YES
+            hints:nil];
     }];
     
+    // 清空粘贴板内容并写入当前选中的富文本内容
     [pboard clearContents];
-    [pboard writeObjects:[NSArray arrayWithObjects:[[self currentSelection] attributedString], nil]];
+    [pboard writeObjects:@[[[self currentSelection] attributedString]]];
     
+    // 创建拖拽项目
+    NSDraggingItem *draggingItem = [[NSDraggingItem alloc] initWithPasteboardWriter:[[self currentSelection] attributedString]];
+    
+    // 设置拖拽项的内容和拖拽图像的位置
     point = CPDFListViewRectFromCenterAndSize([theEvent locationInPDFListView:self], [dragImage size]).origin;
-    [self dragImage:dragImage at:point offset:NSZeroSize event:theEvent pasteboard:pboard source:self slideBack:YES];
+    NSRect draggingFrame = NSMakeRect(point.x, point.y, dragImage.size.width, dragImage.size.height);
+    [draggingItem setDraggingFrame:draggingFrame contents:dragImage];
+    
+    // 开始拖拽会话
+    [self beginDraggingSessionWithItems:@[draggingItem] event:theEvent source:self];
     
     return YES;
 }