1414
1515static NSString * const DVTFontAndColorSourceTextSettingsChangedNotification = @" DVTFontAndColorSourceTextSettingsChangedNotification" ;
1616
17- @interface SCMiniMapView ()
17+ @interface SCMiniMapView () < NSLayoutManagerDelegate >
1818
1919@property (nonatomic , strong ) NSColor *backgroundColor;
2020@property (nonatomic , strong ) NSFont *font;
2121
2222@end
2323
2424@implementation SCMiniMapView
25+ @synthesize backgroundColor = _backgroundColor;
26+
27+ - (void )dealloc
28+ {
29+ [[NSNotificationCenter defaultCenter ] removeObserver: self ];
30+ }
2531
2632- (id )initWithFrame : (NSRect )frame
2733{
@@ -53,23 +59,17 @@ - (id)initWithFrame:(NSRect)frame
5359 return self;
5460}
5561
56- - (void )dealloc
57- {
58- [[NSNotificationCenter defaultCenter ] removeObserver: self ];
59- }
60-
6162#pragma mark - Lazy Initialization
6263
6364- (NSTextView *)textView
6465{
6566 if (_textView == nil ) {
66- _textView = [[NSTextView alloc ] initWithFrame: self .bounds];
67+ _textView = [[NSClassFromString (@" DVTSourceTextView" ) alloc ] initWithFrame: self .bounds];
68+
6769 [_textView setBackgroundColor: [NSColor clearColor ]];
6870
6971 [_textView.textContainer setLineFragmentPadding: 0 .0f ];
7072
71- [_textView.layoutManager setDelegate: self ];
72-
7373 [_textView setAllowsUndo: NO ];
7474 [_textView setAllowsImageEditing: NO ];
7575 [_textView setAutomaticDashSubstitutionEnabled: NO ];
@@ -87,8 +87,12 @@ - (NSTextView *)textView
8787 [self setDocumentView: _textView];
8888
8989 [self updateTheme ];
90+
91+ [[NSNotificationCenter defaultCenter ] removeObserver: _textView name: DVTFontAndColorSourceTextSettingsChangedNotification object: nil ];
9092 }
9193
94+ [_textView.layoutManager setDelegate: self ];
95+
9296 return _textView;
9397}
9498
@@ -186,21 +190,21 @@ - (void)updateTextView
186190 if (mutableAttributedString.length == 0 ) {
187191 return ;
188192 }
189-
193+
190194 __block NSMutableParagraphStyle *style;
191-
192- [mutableAttributedString enumerateAttribute: NSParagraphStyleAttributeName
193- inRange: NSMakeRange (0 , mutableAttributedString.length)
194- options: 0
195- usingBlock: ^(id value, NSRange range, BOOL *stop) {
195+
196+ [mutableAttributedString enumerateAttribute: NSParagraphStyleAttributeName
197+ inRange: NSMakeRange (0 , mutableAttributedString.length)
198+ options: 0
199+ usingBlock: ^(id value, NSRange range, BOOL *stop) {
196200 style = [value mutableCopy ];
197201 *stop = YES ;
198202 }];
199203
200204
201205 [style setTabStops: @[]];
202- [style setDefaultTabInterval: style.defaultTabInterval * kDefaultZoomLevel ];
203-
206+ [style setDefaultTabInterval: style.defaultTabInterval * kDefaultZoomLevel ];
207+
204208 [mutableAttributedString setAttributes: @{NSFontAttributeName : self.font , NSParagraphStyleAttributeName : style} range: NSMakeRange (0 , mutableAttributedString.length)];
205209
206210 [self .textView.textStorage setAttributedString: mutableAttributedString];
@@ -238,30 +242,25 @@ - (void)updateSelectionView
238242 selectionViewFrame.origin .y = self.editorScrollView .contentView .bounds .origin .y * ratio;
239243 }
240244
241- [self .selectionView setFrame: selectionViewFrame];
245+ [self .selectionView setFrame: selectionViewFrame];
242246}
243247
244248#pragma mark - NSLayoutManagerDelegate
245249
246250- (void )layoutManager : (NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer : (NSTextContainer *)textContainer atEnd : (BOOL )layoutFinished
247251{
248- if ([layoutManager isEqual: self .editorTextView.layoutManager]) {
249- [(id <NSLayoutManagerDelegate >)self .editorTextView layoutManager: layoutManager
250- didCompleteLayoutForTextContainer: textContainer
251- atEnd: layoutFinished];
252- }
253- else if (layoutFinished) {
252+ if (layoutFinished) {
254253 [self updateSelectionView ];
255254 }
256255}
257256
258257- (NSDictionary *)layoutManager : (NSLayoutManager *)layoutManager shouldUseTemporaryAttributes : (NSDictionary *)attrs forDrawingToScreen : (BOOL )toScreen atCharacterIndex : (NSUInteger )charIndex effectiveRange : (NSRangePointer )effectiveCharRange
259258{
260- return [( id < NSLayoutManagerDelegate >) self .editorTextView layoutManager: layoutManager
261- shouldUseTemporaryAttributes: attrs
262- forDrawingToScreen: toScreen
263- atCharacterIndex: charIndex
264- effectiveRange: effectiveCharRange];
259+ return [self .editorTextView.layoutManager.delegate layoutManager: layoutManager
260+ shouldUseTemporaryAttributes: attrs
261+ forDrawingToScreen: toScreen
262+ atCharacterIndex: charIndex
263+ effectiveRange: effectiveCharRange];
265264}
266265
267266#pragma mark - Navigation
0 commit comments