diff --git a/MMBackend.m b/MMBackend.m index b82e17a117..0a9f28441a 100644 --- a/MMBackend.m +++ b/MMBackend.m @@ -1120,7 +1120,6 @@ static int specialKeyToNSKey(int key); do_cmdline_cmd((char_u*)[cmd UTF8String]); -#if 1 // This code was taken from the end of gui_handle_drop(). update_screen(NOT_VALID); setcursor(); @@ -1128,7 +1127,27 @@ static int specialKeyToNSKey(int key); gui_update_cursor(FALSE, FALSE); gui_mch_flush(); #endif -#endif +#endif // FEAT_DND + } else if (DropStringMsgID == msgid) { +#ifdef FEAT_DND + char_u dropkey[3] = { CSI, KS_EXTRA, (char_u)KE_DROP }; + const void *bytes = [data bytes]; + int len = *((int*)bytes); bytes += sizeof(int); + NSMutableString *string = [NSMutableString stringWithUTF8String:bytes]; + + // Replace unrecognized end-of-line sequences with \x0a (line feed). + NSRange range = { 0, [string length] }; + unsigned n = [string replaceOccurrencesOfString:@"\x0d\x0a" + withString:@"\x0a" options:0 + range:range]; + if (0 == n) { + n = [string replaceOccurrencesOfString:@"\x0d" withString:@"\x0a" + options:0 range:range]; + } + + len = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + dnd_yank_drag_data((char_u*)[string UTF8String], len); + add_to_input_buf(dropkey, sizeof(dropkey)); #endif // FEAT_DND } else { NSLog(@"WARNING: Unknown message received (msgid=%d)", msgid); diff --git a/MMTextView.m b/MMTextView.m index a373079cf4..2747ecbb3a 100644 --- a/MMTextView.m +++ b/MMTextView.m @@ -262,14 +262,15 @@ #if 1 - (NSArray *)acceptableDragTypes { - return [NSArray arrayWithObjects:NSFilenamesPboardType, nil]; + return [NSArray arrayWithObjects:NSFilenamesPboardType, + NSStringPboardType, nil]; } - (BOOL)performDragOperation:(id )sender { NSPasteboard *pboard = [sender draggingPasteboard]; - if ( [[pboard types] containsObject:NSFilenamesPboardType] ) { + if ([[pboard types] containsObject:NSFilenamesPboardType]) { NSArray *files = [pboard propertyListForType:NSFilenamesPboardType]; int i, numberOfFiles = [files count]; NSMutableData *data = [NSMutableData data]; @@ -299,6 +300,16 @@ [[self vimController] sendMessage:DropFilesMsgID data:data wait:NO]; return YES; + } else if ([[pboard types] containsObject:NSStringPboardType]) { + NSString *string = [pboard stringForType:NSStringPboardType]; + NSMutableData *data = [NSMutableData data]; + int len = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding] + 1; + + [data appendBytes:&len length:sizeof(int)]; + [data appendBytes:[string UTF8String] length:len]; + + [[self vimController] sendMessage:DropStringMsgID data:data wait:NO]; + return YES; } return NO; @@ -312,6 +323,9 @@ if ( [[pboard types] containsObject:NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy) ) return NSDragOperationCopy; + if ( [[pboard types] containsObject:NSStringPboardType] + && (sourceDragMask & NSDragOperationCopy) ) + return NSDragOperationCopy; return NSDragOperationNone; } @@ -324,6 +338,9 @@ if ( [[pboard types] containsObject:NSFilenamesPboardType] && (sourceDragMask & NSDragOperationCopy) ) return NSDragOperationCopy; + if ( [[pboard types] containsObject:NSStringPboardType] + && (sourceDragMask & NSDragOperationCopy) ) + return NSDragOperationCopy; return NSDragOperationNone; } diff --git a/MacVim.h b/MacVim.h index f0032b7ac4..bb7131cfa1 100644 --- a/MacVim.h +++ b/MacVim.h @@ -91,6 +91,7 @@ enum { SetDefaultColorsMsgID, ExecuteActionMsgID, DropFilesMsgID, + DropStringMsgID, }; diff --git a/gui_macvim.m b/gui_macvim.m index e332338d63..33b44cde8d 100644 --- a/gui_macvim.m +++ b/gui_macvim.m @@ -485,7 +485,7 @@ clip_mch_request_selection(VimClipboard *cbd) [NSArray arrayWithObject:NSStringPboardType]]; if (type) { NSMutableString *string = - [[pb stringForType:NSStringPboardType] mutableCopy]; + [[pb stringForType:NSStringPboardType] mutableCopy]; // Replace unrecognized end-of-line sequences with \x0a (line feed). NSRange range = { 0, [string length] };