|
22 | 22 | #import "DVTFontAndColorTheme.h" |
23 | 23 | #import "DVTPreferenceSetManager.h" |
24 | 24 |
|
| 25 | +#import "DVTFoldingManager.h" |
| 26 | + |
25 | 27 | const CGFloat kBackgroundColorShadowLevel = 0.1f; |
26 | 28 | const CGFloat kHighlightColorAlphaLevel = 0.3f; |
27 | 29 | const CGFloat kDurationBetweenInvalidations = 0.5f; |
|
35 | 37 | static NSString * const IDESourceCodeEditorTextViewBoundsDidChangeNotification = @"IDESourceCodeEditorTextViewBoundsDidChangeNotification"; |
36 | 38 | static NSString * const DVTFontAndColorSourceTextSettingsChangedNotification = @"DVTFontAndColorSourceTextSettingsChangedNotification"; |
37 | 39 |
|
38 | | -@interface SCXcodeMinimapView () <NSLayoutManagerDelegate> |
| 40 | +@interface SCXcodeMinimapView () <NSLayoutManagerDelegate, DVTFoldingManagerDelegate> |
39 | 41 |
|
40 | 42 | @property (nonatomic, strong) IDESourceCodeEditor *editor; |
41 | 43 | @property (nonatomic, strong) NSScrollView *editorScrollView; |
@@ -67,8 +69,11 @@ - (instancetype)initWithFrame:(NSRect)frame editor:(IDESourceCodeEditor *)editor |
67 | 69 | if (self = [super initWithFrame:frame]) |
68 | 70 | { |
69 | 71 | self.editor = editor; |
| 72 | + |
70 | 73 | self.editorScrollView = editor.scrollView; |
| 74 | + |
71 | 75 | self.editorTextView = editor.textView; |
| 76 | + [self.editorTextView.foldingManager setDelegate:self]; |
72 | 77 |
|
73 | 78 | [self setWantsLayer:YES]; |
74 | 79 | [self setAutoresizingMask:NSViewMinXMargin | NSViewHeightSizable]; |
@@ -106,11 +111,11 @@ - (instancetype)initWithFrame:(NSRect)frame editor:(IDESourceCodeEditor *)editor |
106 | 111 | }]; |
107 | 112 |
|
108 | 113 | [[NSNotificationCenter defaultCenter] addObserverForName:SCXcodeMinimapHighlightCommentsChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) { |
109 | | - [weakSelf invalidateVisibleMinimapRange]; |
| 114 | + [weakSelf invalidateDisplayForVisibleMinimapRange]; |
110 | 115 | }]; |
111 | 116 |
|
112 | 117 | [[NSNotificationCenter defaultCenter] addObserverForName:SCXcodeMinimapHighlightPreprocessorChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) { |
113 | | - [weakSelf invalidateVisibleMinimapRange]; |
| 118 | + [weakSelf invalidateDisplayForVisibleMinimapRange]; |
114 | 119 | }]; |
115 | 120 |
|
116 | 121 | [[NSNotificationCenter defaultCenter] addObserverForName:SCXcodeMinimapHideEditorScrollerChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) { |
@@ -165,8 +170,8 @@ - (NSDictionary *)layoutManager:(NSLayoutManager *)layoutManager |
165 | 170 |
|
166 | 171 | // Delay invalidation for performance reasons and attempt a full range invalidation later |
167 | 172 | if(!self.shouldAllowFullSyntaxHighlight) { |
168 | | - [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(invalidateVisibleMinimapRange) object:nil]; |
169 | | - [self performSelector:@selector(invalidateVisibleMinimapRange) withObject:nil afterDelay:kDurationBetweenInvalidations]; |
| 173 | + [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(invalidateDisplayForVisibleMinimapRange) object:nil]; |
| 174 | + [self performSelector:@selector(invalidateDisplayForVisibleMinimapRange) withObject:nil afterDelay:kDurationBetweenInvalidations]; |
170 | 175 |
|
171 | 176 | return @{NSForegroundColorAttributeName : self.theme.sourcePlainTextColor}; |
172 | 177 | } |
@@ -201,16 +206,29 @@ - (NSDictionary *)layoutManager:(NSLayoutManager *)layoutManager |
201 | 206 | return @{NSForegroundColorAttributeName : color}; |
202 | 207 | } |
203 | 208 |
|
204 | | -- (void)invalidateVisibleMinimapRange |
| 209 | +- (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer atEnd:(BOOL)layoutFinishedFlag |
205 | 210 | { |
206 | | - self.shouldAllowFullSyntaxHighlight = YES; |
207 | | - NSRange visibleMinimapRange = [self.textView visibleCharacterRange]; |
208 | | - [self.textView.layoutManager invalidateDisplayForCharacterRange:visibleMinimapRange]; |
| 211 | + self.shouldAllowFullSyntaxHighlight = NO; |
209 | 212 | } |
210 | 213 |
|
211 | | -- (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer atEnd:(BOOL)layoutFinishedFlag |
| 214 | +#pragma mark - DVTFoldingManagerDelegate |
| 215 | + |
| 216 | +- (void)foldingManager:(DVTFoldingManager *)foldingManager didFoldRange:(NSRange)range |
212 | 217 | { |
213 | | - self.shouldAllowFullSyntaxHighlight = NO; |
| 218 | + [(DVTLayoutManager *)self.editorTextView.layoutManager foldingManager:foldingManager didFoldRange:range]; |
| 219 | + |
| 220 | + [self.textView.foldingManager foldRange:range]; |
| 221 | + |
| 222 | + [self invalidateLayoutForVisibleMinimapRange]; |
| 223 | +} |
| 224 | + |
| 225 | +- (void)foldingManager:(DVTFoldingManager *)foldingManager didUnfoldRange:(NSRange)range |
| 226 | +{ |
| 227 | + [(DVTLayoutManager *)self.editorTextView.layoutManager foldingManager:foldingManager didUnfoldRange:range]; |
| 228 | + |
| 229 | + [self.textView.foldingManager unfoldRange:range]; |
| 230 | + |
| 231 | + [self invalidateLayoutForVisibleMinimapRange]; |
214 | 232 | } |
215 | 233 |
|
216 | 234 | #pragma mark - Navigation |
@@ -326,18 +344,17 @@ - (void)resizeWithOldSuperviewSize:(NSSize)oldSize |
326 | 344 |
|
327 | 345 | #pragma mark - Helpers |
328 | 346 |
|
329 | | -- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay cancelPreviousRequest:(BOOL)cancel { |
330 | | - if (cancel) { |
331 | | - [NSObject cancelPreviousPerformRequestsWithTarget:self]; |
332 | | - } |
333 | | - |
334 | | - [self performSelector:@selector(delayedAddOperation:) |
335 | | - withObject:[NSBlockOperation blockOperationWithBlock:block] |
336 | | - afterDelay:delay]; |
| 347 | +- (void)invalidateDisplayForVisibleMinimapRange |
| 348 | +{ |
| 349 | + self.shouldAllowFullSyntaxHighlight = YES; |
| 350 | + NSRange visibleMinimapRange = [self.textView visibleCharacterRange]; |
| 351 | + [self.textView.layoutManager invalidateDisplayForCharacterRange:visibleMinimapRange]; |
337 | 352 | } |
338 | 353 |
|
339 | | -- (void)delayedAddOperation:(NSOperation *)operation { |
340 | | - [[NSOperationQueue currentQueue] addOperation:operation]; |
| 354 | +- (void)invalidateLayoutForVisibleMinimapRange |
| 355 | +{ |
| 356 | + NSRange visibleMinimapRange = [self.textView visibleCharacterRange]; |
| 357 | + [self.textView.layoutManager invalidateLayoutForCharacterRange:visibleMinimapRange actualCharacterRange:nil]; |
341 | 358 | } |
342 | 359 |
|
343 | 360 | @end |
0 commit comments