1414@interface SCMiniMapView ()
1515
1616@property (nonatomic , retain ) NSColor *backgroundColor;
17+ @property (nonatomic , retain ) NSFont *font;
1718
1819@end
1920
@@ -56,6 +57,8 @@ - (void)dealloc
5657
5758 [_selectionView release ];
5859 [_textView release ];
60+ [_backgroundColor release ];
61+ [_font release ];
5962 [super dealloc ];
6063}
6164
@@ -107,6 +110,44 @@ - (SCSelectionView *)selectionView
107110 return _selectionView;
108111}
109112
113+ - (NSFont *)font
114+ {
115+ if (_font == nil ) {
116+ _font = [NSFont fontWithName: @" Menlo" size: 11 * kDefaultZoomLevel ];
117+
118+ Class DVTFontAndColorThemeClass = NSClassFromString (@" DVTFontAndColorTheme" );
119+ if ([DVTFontAndColorThemeClass respondsToSelector: @selector (currentTheme )]) {
120+
121+ NSObject *theme = [DVTFontAndColorThemeClass performSelector: @selector (currentTheme )];
122+ if ([theme respondsToSelector: @selector (sourcePlainTextFont )]) {
123+ NSFont *themeFont = [theme performSelector: @selector (sourcePlainTextFont )];
124+ self.font = [NSFont fontWithName: themeFont.familyName size: themeFont.pointSize * kDefaultZoomLevel ];
125+ }
126+ }
127+ }
128+
129+ return _font;
130+ }
131+
132+ - (NSColor *)backgroundColor
133+ {
134+ if (_backgroundColor == nil ) {
135+ _backgroundColor = [[NSColor clearColor ] shadowWithLevel: kDefaultShadowLevel ];
136+
137+ Class DVTFontAndColorThemeClass = NSClassFromString (@" DVTFontAndColorTheme" );
138+ if ([DVTFontAndColorThemeClass respondsToSelector: @selector (currentTheme )]) {
139+
140+ NSObject *theme = [DVTFontAndColorThemeClass performSelector: @selector (currentTheme )];
141+ if ([theme respondsToSelector: @selector (sourceTextBackgroundColor )]) {
142+ NSColor *themeBackgroundColor = [theme performSelector: @selector (sourceTextBackgroundColor )];
143+ self.backgroundColor = [themeBackgroundColor shadowWithLevel: kDefaultShadowLevel ];
144+ }
145+ }
146+ }
147+
148+ return _backgroundColor;
149+ }
150+
110151#pragma mark - Show/Hide
111152
112153- (void )show
@@ -134,19 +175,10 @@ - (void)hide
134175
135176- (void )updateTheme
136177{
137- NSColor *miniMapBackgroundColor = [NSColor clearColor ];
138- Class DVTFontAndColorThemeClass = NSClassFromString (@" DVTFontAndColorTheme" );
139-
140- if ([DVTFontAndColorThemeClass respondsToSelector: @selector (currentTheme )]) {
141-
142- NSObject *theme = [DVTFontAndColorThemeClass performSelector: @selector (currentTheme )];
143- if ([theme respondsToSelector: @selector (sourceTextBackgroundColor )]) {
144- miniMapBackgroundColor = [theme performSelector: @selector (sourceTextBackgroundColor )];
145- }
146- }
178+ [self setFont: nil ];
179+ [self updateTextView ];
147180
148- self.backgroundColor = [miniMapBackgroundColor shadowWithLevel: kDefaultShadowLevel ];
149- [self .textView.textStorage addAttribute: NSBackgroundColorAttributeName value: self .backgroundColor range: NSMakeRange (0 , self .textView.textStorage.length)];
181+ [self setBackgroundColor: nil ];
150182 [self .selectionView setSelectionColor: nil ];
151183}
152184
@@ -162,19 +194,9 @@ - (void)updateTextView
162194 return ;
163195 }
164196
165- [mutableAttributedString enumerateAttributesInRange: NSMakeRange (0 , mutableAttributedString.length) options: NSAttributedStringEnumerationReverse usingBlock:
166- ^(NSDictionary *attributes, NSRange range, BOOL *stop) {
167-
168- NSFont *font = [attributes objectForKey: NSFontAttributeName ];
169- NSFont *newFont = [NSFont fontWithName: font.familyName size: font.pointSize * kDefaultZoomLevel ];
170-
171- NSMutableDictionary *mutableAttributes = [NSMutableDictionary dictionaryWithDictionary: attributes];
172- [mutableAttributes setObject: newFont forKey: NSFontAttributeName ];
173- [mutableAttributedString setAttributes: mutableAttributes range: range];
174- }];
197+ [mutableAttributedString setAttributes: @{NSFontAttributeName : self.font , NSBackgroundColorAttributeName : self.backgroundColor } range: NSMakeRange (0 , mutableAttributedString.length)];
175198
176199 [self .textView.textStorage setAttributedString: mutableAttributedString];
177- [self .textView.textStorage addAttribute: NSBackgroundColorAttributeName value: self .backgroundColor range: NSMakeRange (0 , self .textView.textStorage.length)];
178200 [mutableAttributedString release ];
179201}
180202
0 commit comments