typing attributes refactoring

This commit is contained in:
daboe01
2015-06-07 21:00:25 +02:00
parent 4987fb5f15
commit aae498509b
+11 -8
View File
@@ -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;
}