|
16 | 16 | #import "DVTSourceNodeTypes.h" |
17 | 17 | #import "DVTFontAndColorTheme.h" |
18 | 18 |
|
19 | | - |
20 | 19 | const CGFloat kDefaultZoomLevel = 0.1f; |
21 | | -const CGFloat kDefaultShadowLevel = 0.1f; |
| 20 | +const CGFloat kBackgroundColorShadowLevel = 0.1f; |
| 21 | +const CGFloat kHighlightColorAlphaLevel = 0.3f; |
| 22 | + |
| 23 | +static NSString * const kXcodeSyntaxCommentNodeName = @"xcode.syntax.comment"; |
| 24 | +static NSString * const kXcodeSyntaxPreprocessorNodeName = @"xcode.syntax.preprocessor"; |
22 | 25 |
|
23 | | -static NSString * const kXcodeSyntaxCommentColor = @"xcode.syntax.comment"; |
24 | | -static NSString * const kXcodeSyntaxPreprocessorColor = @"xcode.syntax.preprocessor"; |
25 | 26 | static NSString * const DVTFontAndColorSourceTextSettingsChangedNotification = @"DVTFontAndColorSourceTextSettingsChangedNotification"; |
26 | 27 |
|
27 | 28 | @interface SCXcodeMinimapView () <NSLayoutManagerDelegate> |
@@ -114,8 +115,26 @@ - (void)setVisible:(BOOL)visible |
114 | 115 | - (NSDictionary *)layoutManager:(NSLayoutManager *)layoutManager shouldUseTemporaryAttributes:(NSDictionary *)attrs forDrawingToScreen:(BOOL)toScreen atCharacterIndex:(NSUInteger)charIndex effectiveRange:(NSRangePointer)effectiveCharRange |
115 | 116 | { |
116 | 117 | DVTTextStorage *storage = [self.editorTextView textStorage]; |
| 118 | + |
| 119 | + short currentNodeId = [storage nodeTypeAtCharacterIndex:charIndex effectiveRange:effectiveCharRange context:nil]; |
| 120 | + |
117 | 121 | NSColor *color = [storage colorAtCharacterIndex:charIndex effectiveRange:effectiveCharRange context:nil]; |
118 | | - return @{NSForegroundColorAttributeName : color}; |
| 122 | + NSColor *backgroundColor = nil; |
| 123 | + |
| 124 | + if(currentNodeId == [DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentNodeName]) { |
| 125 | + NSColor *color = [[[DVTFontAndColorTheme currentTheme] syntaxColorsByNodeType] pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentNodeName]]; |
| 126 | + backgroundColor = [NSColor colorWithCalibratedRed:color.redComponent green:color.greenComponent blue:color.blueComponent alpha:kHighlightColorAlphaLevel]; |
| 127 | + } else if(currentNodeId == [DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxPreprocessorNodeName]) { |
| 128 | + NSColor *color = [[[DVTFontAndColorTheme currentTheme] syntaxColorsByNodeType] pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxPreprocessorNodeName]]; |
| 129 | + backgroundColor = [NSColor colorWithCalibratedRed:color.redComponent green:color.greenComponent blue:color.blueComponent alpha:kHighlightColorAlphaLevel]; |
| 130 | + } |
| 131 | + |
| 132 | + if(backgroundColor) { |
| 133 | + NSColor *foregroundColor = [[DVTFontAndColorTheme currentTheme] sourceTextBackgroundColor]; |
| 134 | + return @{NSForegroundColorAttributeName : foregroundColor, NSBackgroundColorAttributeName : backgroundColor}; |
| 135 | + } else { |
| 136 | + return @{NSForegroundColorAttributeName : color}; |
| 137 | + } |
119 | 138 | } |
120 | 139 |
|
121 | 140 | - (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer atEnd:(BOOL)layoutFinished |
@@ -188,31 +207,19 @@ - (void)handleMouseEvent:(NSEvent *)theEvent |
188 | 207 | #pragma mark - Theme |
189 | 208 |
|
190 | 209 | - (void)updateTheme |
191 | | -{ |
192 | | - [self.scrollView setBackgroundColor:self.backgroundColor]; |
193 | | - [self.textView setBackgroundColor:self.backgroundColor]; |
194 | | - [self.selectionView setSelectionColor:nil]; |
195 | | -} |
196 | | - |
197 | | -- (NSColor *)backgroundColor |
198 | 210 | { |
199 | 211 | DVTFontAndColorTheme *theme = [DVTFontAndColorTheme currentTheme]; |
| 212 | + NSColor *backgroundColor = [theme.sourceTextBackgroundColor shadowWithLevel:kBackgroundColorShadowLevel]; |
200 | 213 |
|
201 | | - if(theme.sourceTextBackgroundColor) { |
202 | | - return [theme.sourceTextBackgroundColor shadowWithLevel:kDefaultShadowLevel]; |
203 | | - } |
| 214 | + [self.scrollView setBackgroundColor:backgroundColor]; |
| 215 | + [self.textView setBackgroundColor:backgroundColor]; |
204 | 216 |
|
205 | | - return [[NSColor clearColor] shadowWithLevel:kDefaultShadowLevel]; |
206 | | -} |
207 | | - |
208 | | -- (NSColor *)commentColor |
209 | | -{ |
210 | | - return [[[DVTFontAndColorTheme currentTheme] syntaxColorsByNodeType] pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentColor]]; |
211 | | -} |
212 | | - |
213 | | -- (NSColor *)preprocessorColor |
214 | | -{ |
215 | | - return [[[DVTFontAndColorTheme currentTheme] syntaxColorsByNodeType] pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxPreprocessorColor]]; |
| 217 | + NSColor *selectionColor = [NSColor colorWithCalibratedRed:(1.0f - [backgroundColor redComponent]) |
| 218 | + green:(1.0f - [backgroundColor greenComponent]) |
| 219 | + blue:(1.0f - [backgroundColor blueComponent]) |
| 220 | + alpha:kHighlightColorAlphaLevel]; |
| 221 | + |
| 222 | + [self.selectionView setSelectionColor:selectionColor]; |
216 | 223 | } |
217 | 224 |
|
218 | 225 | #pragma mark - Autoresizing |
|
0 commit comments