14
14
15
15
static NSString * const DVTFontAndColorSourceTextSettingsChangedNotification = @" DVTFontAndColorSourceTextSettingsChangedNotification" ;
16
16
17
- @interface SCMiniMapView ()
17
+ @interface SCMiniMapView () < NSLayoutManagerDelegate >
18
18
19
19
@property (nonatomic , strong ) NSColor *backgroundColor;
20
20
@property (nonatomic , strong ) NSFont *font;
21
21
22
22
@end
23
23
24
24
@implementation SCMiniMapView
25
+ @synthesize backgroundColor = _backgroundColor;
26
+
27
+ - (void )dealloc
28
+ {
29
+ [[NSNotificationCenter defaultCenter ] removeObserver: self ];
30
+ }
25
31
26
32
- (id )initWithFrame : (NSRect )frame
27
33
{
@@ -53,23 +59,17 @@ - (id)initWithFrame:(NSRect)frame
53
59
return self;
54
60
}
55
61
56
- - (void )dealloc
57
- {
58
- [[NSNotificationCenter defaultCenter ] removeObserver: self ];
59
- }
60
-
61
62
#pragma mark - Lazy Initialization
62
63
63
64
- (NSTextView *)textView
64
65
{
65
66
if (_textView == nil ) {
66
- _textView = [[NSTextView alloc ] initWithFrame: self .bounds];
67
+ _textView = [[NSClassFromString (@" DVTSourceTextView" ) alloc ] initWithFrame: self .bounds];
68
+
67
69
[_textView setBackgroundColor: [NSColor clearColor ]];
68
70
69
71
[_textView.textContainer setLineFragmentPadding: 0 .0f ];
70
72
71
- [_textView.layoutManager setDelegate: self ];
72
-
73
73
[_textView setAllowsUndo: NO ];
74
74
[_textView setAllowsImageEditing: NO ];
75
75
[_textView setAutomaticDashSubstitutionEnabled: NO ];
@@ -87,8 +87,12 @@ - (NSTextView *)textView
87
87
[self setDocumentView: _textView];
88
88
89
89
[self updateTheme ];
90
+
91
+ [[NSNotificationCenter defaultCenter ] removeObserver: _textView name: DVTFontAndColorSourceTextSettingsChangedNotification object: nil ];
90
92
}
91
93
94
+ [_textView.layoutManager setDelegate: self ];
95
+
92
96
return _textView;
93
97
}
94
98
@@ -186,21 +190,21 @@ - (void)updateTextView
186
190
if (mutableAttributedString.length == 0 ) {
187
191
return ;
188
192
}
189
-
193
+
190
194
__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) {
196
200
style = [value mutableCopy ];
197
201
*stop = YES ;
198
202
}];
199
203
200
204
201
205
[style setTabStops: @[]];
202
- [style setDefaultTabInterval: style.defaultTabInterval * kDefaultZoomLevel ];
203
-
206
+ [style setDefaultTabInterval: style.defaultTabInterval * kDefaultZoomLevel ];
207
+
204
208
[mutableAttributedString setAttributes: @{NSFontAttributeName : self.font , NSParagraphStyleAttributeName : style} range: NSMakeRange (0 , mutableAttributedString.length)];
205
209
206
210
[self .textView.textStorage setAttributedString: mutableAttributedString];
@@ -238,30 +242,25 @@ - (void)updateSelectionView
238
242
selectionViewFrame.origin .y = self.editorScrollView .contentView .bounds .origin .y * ratio;
239
243
}
240
244
241
- [self .selectionView setFrame: selectionViewFrame];
245
+ [self .selectionView setFrame: selectionViewFrame];
242
246
}
243
247
244
248
#pragma mark - NSLayoutManagerDelegate
245
249
246
250
- (void )layoutManager : (NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer : (NSTextContainer *)textContainer atEnd : (BOOL )layoutFinished
247
251
{
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) {
254
253
[self updateSelectionView ];
255
254
}
256
255
}
257
256
258
257
- (NSDictionary *)layoutManager : (NSLayoutManager *)layoutManager shouldUseTemporaryAttributes : (NSDictionary *)attrs forDrawingToScreen : (BOOL )toScreen atCharacterIndex : (NSUInteger )charIndex effectiveRange : (NSRangePointer )effectiveCharRange
259
258
{
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];
265
264
}
266
265
267
266
#pragma mark - Navigation
0 commit comments