Skip to content
Snippets Groups Projects
Commit e802c952 authored by George Nachman's avatar George Nachman
Browse files

When copying with styles, copy inline images too.

parent 40ad7e6b
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3542,9 +3542,10 @@ static double EuclideanDistance(NSPoint p1, NSPoint p2) {
}
[pboard declareTypes:types owner:self];
if (copyAttributedString) {
NSData *RTFData = [copyAttributedString RTFFromRange:NSMakeRange(0, [copyAttributedString length])
documentAttributes:@{}];
[pboard setData:RTFData forType:NSRTFPboardType];
// I used to convert this to RTF data using
// RTFFromRange:documentAttributes: but images wouldn't paste right.
[pboard clearContents];
[pboard writeObjects:@[ copyAttributedString ]];
}
// I used to do
// [pboard setString:[copyAttributedString string] forType:NSStringPboardType]
Loading
Loading
@@ -4458,41 +4459,8 @@ static double EuclideanDistance(NSPoint p1, NSPoint p2) {
[panel setExtensionHidden:NO];
 
if ([panel runModal] == NSModalResponseOK) {
NSBitmapImageFileType fileType = NSPNGFileType;
NSString *filename = [panel legacyFilename];
if ([filename hasSuffix:@".bmp"]) {
fileType = NSBMPFileType;
} else if ([filename hasSuffix:@".gif"]) {
fileType = NSGIFFileType;
} else if ([filename hasSuffix:@".jp2"]) {
fileType = NSJPEG2000FileType;
} else if ([filename hasSuffix:@".jpg"] || [filename hasSuffix:@".jpeg"]) {
fileType = NSJPEGFileType;
} else if ([filename hasSuffix:@".png"]) {
fileType = NSPNGFileType;
} else if ([filename hasSuffix:@".tiff"]) {
fileType = NSTIFFFileType;
}
NSData *data = nil;
NSDictionary *universalTypeToCocoaMap = @{ (NSString *)kUTTypeBMP: @(NSBMPFileType),
(NSString *)kUTTypeGIF: @(NSGIFFileType),
(NSString *)kUTTypeJPEG2000: @(NSJPEG2000FileType),
(NSString *)kUTTypeJPEG: @(NSJPEGFileType),
(NSString *)kUTTypePNG: @(NSPNGFileType),
(NSString *)kUTTypeTIFF: @(NSTIFFFileType) };
NSString *imageType = imageInfo.imageType;
if (imageType) {
NSNumber *nsTypeNumber = universalTypeToCocoaMap[imageType];
if (nsTypeNumber.integerValue == fileType) {
data = imageInfo.data;
}
}
if (!data) {
NSBitmapImageRep *rep = [imageInfo.image.images.firstObject bitmapImageRep];
data = [rep representationUsingType:fileType properties:@{}];
}
[data writeToFile:filename atomically:NO];
[imageInfo saveToFile:filename];
}
}
 
Loading
Loading
Loading
Loading
@@ -74,4 +74,7 @@ extern NSString *const iTermImageDidLoad;
// Coded representation
- (NSDictionary *)dictionary;
 
// Format inferred from extension
- (void)saveToFile:(NSString *)filename;
@end
Loading
Loading
@@ -136,6 +136,43 @@ NSString *const iTermImageDidLoad = @"iTermImageDidLoad";
[super dealloc];
}
 
- (void)saveToFile:(NSString *)filename {
NSBitmapImageFileType fileType = NSPNGFileType;
if ([filename hasSuffix:@".bmp"]) {
fileType = NSBMPFileType;
} else if ([filename hasSuffix:@".gif"]) {
fileType = NSGIFFileType;
} else if ([filename hasSuffix:@".jp2"]) {
fileType = NSJPEG2000FileType;
} else if ([filename hasSuffix:@".jpg"] || [filename hasSuffix:@".jpeg"]) {
fileType = NSJPEGFileType;
} else if ([filename hasSuffix:@".png"]) {
fileType = NSPNGFileType;
} else if ([filename hasSuffix:@".tiff"]) {
fileType = NSTIFFFileType;
}
NSData *data = nil;
NSDictionary *universalTypeToCocoaMap = @{ (NSString *)kUTTypeBMP: @(NSBMPFileType),
(NSString *)kUTTypeGIF: @(NSGIFFileType),
(NSString *)kUTTypeJPEG2000: @(NSJPEG2000FileType),
(NSString *)kUTTypeJPEG: @(NSJPEGFileType),
(NSString *)kUTTypePNG: @(NSPNGFileType),
(NSString *)kUTTypeTIFF: @(NSTIFFFileType) };
NSString *imageType = self.imageType;
if (imageType) {
NSNumber *nsTypeNumber = universalTypeToCocoaMap[imageType];
if (nsTypeNumber.integerValue == fileType) {
data = self.data;
}
}
if (!data) {
NSBitmapImageRep *rep = [self.image.images.firstObject bitmapImageRep];
data = [rep representationUsingType:fileType properties:@{}];
}
[data writeToFile:filename atomically:NO];
}
- (void)setImageFromImage:(iTermImage *)image data:(NSData *)data {
[_dictionary release];
_dictionary = nil;
Loading
Loading
Loading
Loading
@@ -8,7 +8,9 @@
 
#import "iTermTextExtractor.h"
#import "DebugLogging.h"
#import "iTermImageInfo.h"
#import "iTermPreferences.h"
#import "iTermSystemVersion.h"
#import "iTermURLStore.h"
#import "NSStringITerm.h"
#import "NSMutableAttributedString+iTerm.h"
Loading
Loading
@@ -1210,9 +1212,34 @@ const NSInteger kLongMaximumWordLength = 100000;
}
const NSUInteger kMaximumOversizeAmountWhenTruncatingHead = 1024 * 100;
int width = [_dataSource width];
__block BOOL lineContainsNonImage = NO;
__block BOOL lineContainsImage = NO;
__block BOOL copiedImage = NO;
[self enumerateCharsInRange:windowedRange
charBlock:^BOOL(screen_char_t *currentLine, screen_char_t theChar, VT100GridCoord coord) {
if (theChar.code == TAB_FILLER && !theChar.complexChar) {
if (theChar.image) {
lineContainsImage = YES;
} else {
lineContainsNonImage = YES;
}
if (theChar.image) {
if (attributeProvider && theChar.foregroundColor == 0 && theChar.backgroundColor == 0) {
iTermImageInfo *imageInfo = GetImageInfo(theChar.code);
NSImage *image = imageInfo.image.images.firstObject;
if (image) {
if (IsElCapitanOrLater()) {
copiedImage = YES;
NSTextAttachment *textAttachment = [[[NSTextAttachment alloc] init] autorelease];
ITERM_IGNORE_PARTIAL_BEGIN
textAttachment.image = imageInfo.image.images.firstObject;
ITERM_IGNORE_PARTIAL_END
NSAttributedString *attributedStringWithAttachment = [NSAttributedString attributedStringWithAttachment:textAttachment];
[result appendAttributedString:attributedStringWithAttachment];
[coords addObject:[NSValue valueWithGridCoord:coord]];
}
}
}
} else if (theChar.code == TAB_FILLER && !theChar.complexChar) {
// Convert orphan tab fillers (those without a subsequent
// tab character) into spaces.
if ([self tabFillerAtIndex:coord.x isOrphanInLine:currentLine]) {
Loading
Loading
@@ -1262,6 +1289,11 @@ const NSInteger kLongMaximumWordLength = 100000;
return NO;
}
eolBlock:^BOOL(unichar code, int numPreceedingNulls, int line) {
BOOL ignore = (!copiedImage && !lineContainsNonImage && lineContainsImage);
copiedImage = lineContainsNonImage = lineContainsImage = NO;
if (ignore) {
return NO;
}
int right;
if (windowedRange.columnWindow.length) {
right = windowedRange.columnWindow.location + windowedRange.columnWindow.length;
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment