From b7d399faf77fbad7e7031e1f0c5d14a99d0bfcbd Mon Sep 17 00:00:00 2001 From: daboe01 Date: Mon, 1 Aug 2016 09:17:05 +0200 Subject: [PATCH] fixed: bold and italic extraction from dom for native paste --- AppKit/CPTextView/CPTextView.j | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 019dbff1d..d02cd3ff7 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -2436,17 +2436,18 @@ var _CPCopyPlaceholder = '-'; forKey:CPForegroundColorAttributeName]; // extract font from the DOM + var fontname = style.getPropertyValue('font-family'), - fontsize = style.getPropertyValue('font-size'), - isBold = style.getPropertyValue('font-weight').indexOf('bold') >= 0, - isItalic = style.getPropertyValue('font-style').indexOf('italic') >= 0; + fontsize = parseInt(style.getPropertyValue('font-size'), 10), + isBold = node.firstChild && node.firstChild.nodeName === 'B' || node.firstChild.firstChild && node.firstChild.firstChild.nodeName === 'B', + isItalic = node.firstChild && node.firstChild.nodeName === 'I' || node.firstChild.firstChild && node.firstChild.firstChild.nodeName === 'I'; if (fontname && fontsize) [styleAttributes setObject:isBold? [CPFont boldFontWithName:fontname size:fontsize italic:isItalic] : [CPFont fontWithName:fontname size:fontsize italic:isItalic] forKey:CPFontAttributeName]; - [rtfdata appendAttributedString: [[CPAttributedString alloc] initWithString:text attributes:styleAttributes]]; + [rtfdata appendAttributedString:[[CPAttributedString alloc] initWithString:text attributes:styleAttributes]]; } }; @@ -2487,8 +2488,6 @@ var _CPCopyPlaceholder = '-'; // this is the native rich chrome path: // we have to construct an CPAttributedString whilst walking the dom and looking at the CSS attributes - // currently, only the text color is extracted. - // FIXME: extract font attributes from the style strings. if (richtext = nativeClipboard.getData('text/html')) { e.preventDefault();