Skip to content

Commit 0f92e2f

Browse files
committed
- added comment and preprocessor instructions highlighting
- cleaned up theme related methods and selection view.
1 parent d62829b commit 0f92e2f

File tree

3 files changed

+33
-63
lines changed

3 files changed

+33
-63
lines changed

SCXcodeMinimap/SCXcodeMinimapSelectionView.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@
1111
@interface SCXcodeMinimapSelectionView : NSView
1212

1313
@property (nonatomic, strong) NSColor *selectionColor;
14-
@property (nonatomic, assign) BOOL shouldInverseColors;
1514

1615
@end

SCXcodeMinimap/SCXcodeMinimapSelectionView.m

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,6 @@ - (void)drawRect:(NSRect)dirtyRect
1818
NSRectFill(dirtyRect);
1919
}
2020

21-
- (NSColor *)selectionColor
22-
{
23-
if(_selectionColor == nil) {
24-
25-
_selectionColor = [NSColor colorWithDeviceRed:0.0f green:0.0f blue:0.0f alpha:0.3f];
26-
27-
NSColor *backgroundColor = [[[DVTFontAndColorTheme currentTheme] sourceTextBackgroundColor] colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
28-
29-
if(self.shouldInverseColors) {
30-
31-
_selectionColor = [NSColor colorWithCalibratedRed:(1.0f - [backgroundColor redComponent])
32-
green:(1.0f - [backgroundColor greenComponent])
33-
blue:(1.0f - [backgroundColor blueComponent])
34-
alpha:0.3f];
35-
} else {
36-
37-
_selectionColor = [NSColor colorWithCalibratedHue:0.0f
38-
saturation:0.0f
39-
brightness:(1.0f - [backgroundColor brightnessComponent])
40-
alpha:0.3f];
41-
}
42-
}
43-
44-
return _selectionColor;
45-
}
46-
4721
- (void)setSelectionColor:(NSColor *)selectionColor
4822
{
4923
if([_selectionColor isEqual:selectionColor]) return;
@@ -52,14 +26,4 @@ - (void)setSelectionColor:(NSColor *)selectionColor
5226
[self setNeedsDisplay:YES];
5327
}
5428

55-
- (void)setShouldInverseColors:(BOOL)shouldInverseColors
56-
{
57-
if(_shouldInverseColors == shouldInverseColors) {
58-
return;
59-
}
60-
61-
_shouldInverseColors = shouldInverseColors;
62-
_selectionColor = nil;
63-
}
64-
6529
@end

SCXcodeMinimap/SCXcodeMinimapView.m

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
#import "DVTSourceNodeTypes.h"
1717
#import "DVTFontAndColorTheme.h"
1818

19-
2019
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";
2225

23-
static NSString * const kXcodeSyntaxCommentColor = @"xcode.syntax.comment";
24-
static NSString * const kXcodeSyntaxPreprocessorColor = @"xcode.syntax.preprocessor";
2526
static NSString * const DVTFontAndColorSourceTextSettingsChangedNotification = @"DVTFontAndColorSourceTextSettingsChangedNotification";
2627

2728
@interface SCXcodeMinimapView () <NSLayoutManagerDelegate>
@@ -114,8 +115,26 @@ - (void)setVisible:(BOOL)visible
114115
- (NSDictionary *)layoutManager:(NSLayoutManager *)layoutManager shouldUseTemporaryAttributes:(NSDictionary *)attrs forDrawingToScreen:(BOOL)toScreen atCharacterIndex:(NSUInteger)charIndex effectiveRange:(NSRangePointer)effectiveCharRange
115116
{
116117
DVTTextStorage *storage = [self.editorTextView textStorage];
118+
119+
short currentNodeId = [storage nodeTypeAtCharacterIndex:charIndex effectiveRange:effectiveCharRange context:nil];
120+
117121
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+
}
119138
}
120139

121140
- (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer atEnd:(BOOL)layoutFinished
@@ -188,31 +207,19 @@ - (void)handleMouseEvent:(NSEvent *)theEvent
188207
#pragma mark - Theme
189208

190209
- (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
198210
{
199211
DVTFontAndColorTheme *theme = [DVTFontAndColorTheme currentTheme];
212+
NSColor *backgroundColor = [theme.sourceTextBackgroundColor shadowWithLevel:kBackgroundColorShadowLevel];
200213

201-
if(theme.sourceTextBackgroundColor) {
202-
return [theme.sourceTextBackgroundColor shadowWithLevel:kDefaultShadowLevel];
203-
}
214+
[self.scrollView setBackgroundColor:backgroundColor];
215+
[self.textView setBackgroundColor:backgroundColor];
204216

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];
216223
}
217224

218225
#pragma mark - Autoresizing

0 commit comments

Comments
 (0)