From aae498509bed8bbb78dced70340a645672cd9ab2 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sun, 7 Jun 2015 21:00:25 +0200 Subject: [PATCH] typing attributes refactoring --- AppKit/CPTextView/CPTextView.j | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index e38212981..c55d3dccf 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -1313,6 +1313,15 @@ var kDelegateRespondsTo_textShouldBeginEditing [self insertLineBreak:sender]; } +- (void)_enrichEssentialTypingAttributes:(CPDictionary)attributes +{ + if (![attributes containsKey:CPFontAttributeName]) + [attributes setObject:[self font] forKey:CPFontAttributeName]; + + if (![attributes containsKey:CPForegroundColorAttributeName]) + [attributes setObject:[self textColor] forKey:CPForegroundColorAttributeName]; +} + - (void)setTypingAttributes:(CPDictionary)attributes { if (!attributes) @@ -1326,12 +1335,7 @@ var kDelegateRespondsTo_textShouldBeginEditing { _typingAttributes = [attributes copy]; - /* check that new attributes contains essentials one's */ - if (![_typingAttributes containsKey:CPFontAttributeName]) - [_typingAttributes setObject:[self font] forKey:CPFontAttributeName]; - - if (![_typingAttributes containsKey:CPForegroundColorAttributeName]) - [_typingAttributes setObject:[self textColor] forKey:CPForegroundColorAttributeName]; + [self _enrichEssentialTypingAttributes:_typingAttributes]; } [[CPNotificationCenter defaultCenter] postNotificationName:CPTextViewDidChangeTypingAttributesNotification @@ -1345,8 +1349,7 @@ var kDelegateRespondsTo_textShouldBeginEditing { var attributes = [[_textStorage attributesAtIndex:CPMaxRange(_selectionRange) effectiveRange:nil] copy]; - if (![attributes containsKey:CPForegroundColorAttributeName]) - [attributes setObject:[self textColor] forKey:CPForegroundColorAttributeName]; + [self _enrichEssentialTypingAttributes:attributes]; return attributes; }