diff --git a/AppKit/CPPasteboard.j b/AppKit/CPPasteboard.j index 5372a5bef..c8429147f 100644 --- a/AppKit/CPPasteboard.j +++ b/AppKit/CPPasteboard.j @@ -44,6 +44,7 @@ CPStringPboardType = @"CPStringPboardType"; CPURLPboardType = @"CPURLPboardType"; CPImagesPboardType = @"CPImagesPboardType"; CPVideosPboardType = @"CPVideosPboardType"; +CPRTFPboardType = @"CPRTFPboardType"; UTF8PboardType = @"public.utf8-plain-text"; diff --git a/AppKit/CPText.j b/AppKit/CPText.j index 70b31a0bc..da3e47a8b 100644 --- a/AppKit/CPText.j +++ b/AppKit/CPText.j @@ -158,11 +158,11 @@ CPKernAttributeName = @"CPKernAttributeName"; - (id)_stringForPasting { var pasteboard = [CPPasteboard generalPasteboard], - // dataForPasting = [pasteboard dataForType:CPRichStringPboardType], + dataForPasting = [pasteboard stringForType:CPRTFPboardType], stringForPasting = [pasteboard stringForType:CPStringPboardType]; - if ([stringForPasting hasPrefix:"{\\rtf1\\ansi"]) - stringForPasting = [[_CPRTFParser new] parseRTF:stringForPasting]; + if (dataForPasting || [stringForPasting hasPrefix:"{\\rtf1\\ansi"]) + stringForPasting = [[_CPRTFParser new] parseRTF:dataForPasting ? dataForPasting : stringForPasting]; if (![self isRichText] && [stringForPasting isKindOfClass:[CPAttributedString class]]) stringForPasting = stringForPasting._string; diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index ffecd7123..f780561a4 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -369,14 +369,9 @@ var kDelegateRespondsTo_textShouldBeginEditing pasteboard = [CPPasteboard generalPasteboard], stringForPasting = [_textStorage attributedSubstringFromRange:CPMakeRangeCopy(selectedRange)]; - // put rich representation on the pasteboad only if we have multliple attributes selected - if (stringForPasting._rangeEntries.length > 1) - { - // [pasteboard declareTypes:[CPStringPboardType, CPRichStringPboardType] owner:nil]; // this does currently do not work due to limitations in cappuccino - var richData = [_CPRTFProducer produceRTF:stringForPasting documentAttributes:@{}]; - // crude hack to make rich pasting possible in chrome and firefox: put rtf on the plain pasteboard - [pasteboard setString:richData forType:CPStringPboardType]; - } + [pasteboard declareTypes:[CPStringPboardType, CPRTFPboardType] owner:nil]; + [pasteboard setString:stringForPasting._string forType:CPStringPboardType]; + [pasteboard setString:richData forType:CPRTFPboardType]; } - (void)paste:(id)sender @@ -2418,11 +2413,17 @@ var _CPCopyPlaceholder = '-'; _CPNativeInputField.onpaste = function(e) { var pasteboard = [CPPasteboard generalPasteboard]; - [pasteboard declareTypes:[CPStringPboardType] owner:nil]; - var data = e.clipboardData.getData('text/plain'); - [pasteboard setString:data forType:CPStringPboardType]; + var data = e.clipboardData.getData('text/plain'), + cappString = [pasteboard stringForType:CPStringPboardType]; + // capp string is invalid -> overwrite with system clipboard + if (cappString !== data) + { + [pasteboard declareTypes:[CPStringPboardType] owner:nil]; + [pasteboard setString:data forType:CPStringPboardType]; + } + var currentFirstResponder = [[CPApp keyWindow] firstResponder]; setTimeout(function(){ // prevent dom-flickering @@ -2440,10 +2441,8 @@ var _CPCopyPlaceholder = '-'; [currentFirstResponder copy:self]; - // dataForPasting = [pasteboard dataForType:CPRichStringPboardType], var stringForPasting = [pasteboard stringForType:CPStringPboardType]; e.clipboardData.setData('text/plain', stringForPasting); - // e.clipboardData.setData('text/rtf', stringForPasting); // does not seem to work return false; } @@ -2462,11 +2461,9 @@ var _CPCopyPlaceholder = '-'; // this is necessary because cut will only execute in the future [currentFirstResponder copy:self]; - //dataForPasting = [pasteboard dataForType:CPRichStringPboardType], var stringForPasting = [pasteboard stringForType:CPStringPboardType]; e.clipboardData.setData('text/plain', stringForPasting); - //e.clipboardData.setData('text/rtf', stringForPasting); // does not seem to work return false; }