new: colorpanel sync

This commit is contained in:
daboe01
2026-06-19 07:18:52 +02:00
parent e67c141921
commit d40a151e05
+26
View File
@@ -1005,6 +1005,25 @@ Sets the selection to a range of characters in response to user action.
if (doOverwrite && _placeholderString == nil && isNewSelection)
[self setTypingAttributes:[_textStorage attributesAtIndex:CPMaxRange(range) effectiveRange:nil]];
// Update the shared CPColorPanel with the active selection color
if ([self _isFirstResponder] && [_textStorage length] > 0)
{
var currentTextColor = [self textColor] || [CPColor blackColor];
if ([self isRichText])
{
var charIndex = _selectionRange.location;
if (charIndex >= [_textStorage length])
charIndex = MAX(0, charIndex - 1);
var attributes = [_textStorage attributesAtIndex:charIndex effectiveRange:nil];
if ([attributes objectForKey:CPForegroundColorAttributeName])
currentTextColor = [attributes objectForKey:CPForegroundColorAttributeName];
}
[[CPColorPanel sharedColorPanel] setColor:currentTextColor];
}
[[CPNotificationCenter defaultCenter] postNotificationName:CPTextViewDidChangeSelectionNotification object:self];
}
@@ -1799,6 +1818,13 @@ Sets the selection to a range of characters in response to user action.
// SYNCHRONIZE ACTIVE PARAGRAPH MARKERS ON TYPING ATTRIBUTES CHANGE
[self updateRuler];
// Synchronize CPColorPanel if text view is active
if ([self _isFirstResponder])
{
var currentTextColor = [_typingAttributes objectForKey:CPForegroundColorAttributeName] || [self textColor] || [CPColor blackColor];
[[CPColorPanel sharedColorPanel] setColor:currentTextColor];
}
[[CPNotificationCenter defaultCenter] postNotificationName:CPTextViewDidChangeTypingAttributesNotification object:self];
// We always clear the saved selection range from the last mouse down event here.