Skip to content

Commit 0327f23

Browse files
committed
Various tweaks.
1 parent 2521609 commit 0327f23

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

SCXcodeMinimap/SCMiniMapView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern const CGFloat kDefaultZoomLevel;
1919
@property (nonatomic, weak) NSScrollView *editorScrollView;
2020
@property (nonatomic, strong) NSTextView *editorTextView;
2121

22-
@property (nonatomic, readonly) NSInteger lastCalculatedLines;
22+
@property (nonatomic, readonly) NSInteger numberOfLines;
2323

2424
- (void)updateTextView;
2525
- (void)updateSelectionView;

SCXcodeMinimap/SCMiniMapView.m

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ @interface SCMiniMapView () <NSLayoutManagerDelegate>
1818

1919
@property (nonatomic, strong) NSColor *backgroundColor;
2020
@property (nonatomic, strong) NSFont *font;
21-
@property (nonatomic, readwrite) NSInteger lastCalculatedLines;
21+
@property (nonatomic, assign) NSInteger numberOfLines;
2222

2323
@end
2424

@@ -187,15 +187,12 @@ - (void)updateTextView
187187
}
188188

189189
typeof(self) __weak weakSelf = self;
190-
NSOperationQueue *background = [[NSOperationQueue alloc] init];
191-
192-
//Run the attributed strings operation on a background thread
193-
[background addOperationWithBlock:^{
190+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
194191
NSMutableAttributedString *mutableAttributedString = [self.editorTextView.textStorage mutableCopy];
195192

196193
if(mutableAttributedString.length == 0) {
197194
//Nothing to do here.
198-
weakSelf.lastCalculatedLines = 0;
195+
weakSelf.numberOfLines = 0;
199196
return;
200197
}
201198

@@ -216,27 +213,25 @@ - (void)updateTextView
216213
[mutableAttributedString setAttributes:@{NSFontAttributeName: weakSelf.font, NSParagraphStyleAttributeName : style} range:NSMakeRange(0, mutableAttributedString.length)];
217214

218215
//Send the text storage update off to the main thread
219-
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
216+
dispatch_async(dispatch_get_main_queue(), ^{
220217
[weakSelf.textView.textStorage setAttributedString:mutableAttributedString];
221218
[weakSelf updateSelectionView];
222-
}];
219+
});
223220

224-
//Now that we've sent that off, let's see how many lines we have while
225-
//we're in here:
221+
//Calculate the total number of lines
226222
[weakSelf calculateLinesFromString:[mutableAttributedString string]];
227-
}];
223+
});
228224
}
229225

230226
- (void)calculateLinesFromString:(NSString *)string
231227
{
232-
NSUInteger stringLength = [string length];
233-
NSInteger numberOfLines = 0;
234-
for (NSInteger index = 0; index < stringLength; numberOfLines++) {
228+
NSInteger count = 0;
229+
for (NSInteger index = 0; index < [string length]; count++) {
235230
index = NSMaxRange([string lineRangeForRange:NSMakeRange(index, 0)]);
236231
}
237232

238233
//Cache the last calculated lines so we can figure out how long we should take to render this minimap.
239-
self.lastCalculatedLines = numberOfLines;
234+
self.numberOfLines = count;
240235
}
241236

242237
- (void)resizeWithOldSuperviewSize:(NSSize)oldSize

SCXcodeMinimap/SCXcodeMinimap.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ - (void)onDocumentDidChange:(NSNotification*)sender
9898
SCMiniMapView *miniMapView = objc_getAssociatedObject([sender object], &kKeyMiniMapView);
9999

100100
//150 lines per multiplier means a 1500 line file should have a delay of 2.5 seconds.
101-
CGFloat multiplier = ceilf((CGFloat)miniMapView.lastCalculatedLines / 150.0f);
101+
CGFloat multiplier = ceilf((CGFloat)miniMapView.numberOfLines / 150.0f);
102102
NSTimeInterval updateInterval = (CGFloat)multiplier * kDefaultUpdateInterval;
103103

104104
[NSObject cancelPreviousPerformRequestsWithTarget:miniMapView selector:@selector(updateTextView) object:nil];

0 commit comments

Comments
 (0)