Skip to content

Commit 4487b62

Browse files
committed
Xcode 6 support + various tweaks and fixes.
1 parent 958bdb6 commit 4487b62

File tree

4 files changed

+41
-37
lines changed

4 files changed

+41
-37
lines changed

SCXcodeMinimap/SCMiniMapView.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
extern const CGFloat kDefaultZoomLevel;
1313

14-
@interface SCMiniMapView : NSScrollView <NSLayoutManagerDelegate>
14+
@interface SCMiniMapView : NSScrollView
1515

1616
@property (nonatomic, strong) NSTextView *textView;
1717
@property (nonatomic, strong) SCSelectionView *selectionView;

SCXcodeMinimap/SCMiniMapView.m

+28-29
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@
1414

1515
static 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

SCXcodeMinimap/SCXcodeMinimap-Info.plist

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<string>A2E4D43F-41F4-4FB9-BB94-7177011C9AED</string>
2828
<string>63FC1C47-140D-42B0-BB4D-A10B2D225574</string>
2929
<string>37B30044-3B14-46BA-ABAA-F01000C27B63</string>
30+
<string>AD68E85B-441B-4301-B564-A45E4919A6AD</string>
3031
</array>
3132
<key>NSHumanReadableCopyright</key>
3233
<string>Copyright © 2013 Stefan Ceriu. All rights reserved.</string>

SCXcodeMinimap/SCXcodeMinimap.m

+11-7
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,28 @@
2121

2222
NSString * const SCXodeMinimapIsInitiallyHidden = @"SCXodeMinimapIsInitiallyHidden";
2323

24+
static const CGFloat kDefaultUpdateInterval = 0.25f;
25+
2426
@implementation SCXcodeMinimap
2527

2628
static SCXcodeMinimap *sharedMinimap = nil;
2729
+ (void)pluginDidLoad:(NSBundle *)plugin {
28-
static dispatch_once_t onceToken;
29-
dispatch_once(&onceToken, ^{
30-
sharedMinimap = [[self alloc] init];
31-
});
30+
static dispatch_once_t onceToken;
31+
dispatch_once(&onceToken, ^{
32+
sharedMinimap = [[self alloc] init];
33+
});
3234
}
3335

3436
- (id)init {
35-
if (self = [super init]) {
37+
if (self = [super init]) {
3638

3739
[self createMenuItem];
3840

3941
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDidFinishSetup:) name:IDESourceCodeEditorDidFinishSetupNotification object:nil];
4042
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDocumentDidChange:) name:IDEEditorDocumentDidChangeNotification object:nil];
4143
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onCodeEditorBoundsChange:) name:IDESourceCodeEditorTextViewBoundsDidChangeNotification object:nil];
4244
}
43-
return self;
45+
return self;
4446
}
4547

4648
- (void)createMenuItem
@@ -94,7 +96,9 @@ - (void)showMiniMap:(NSMenuItem *)sender
9496
- (void)onDocumentDidChange:(NSNotification*)sender
9597
{
9698
SCMiniMapView *miniMapView = objc_getAssociatedObject([sender object], &kKeyMiniMapView);
97-
[miniMapView updateTextView];
99+
100+
[NSObject cancelPreviousPerformRequestsWithTarget:miniMapView selector:@selector(updateTextView) object:nil];
101+
[miniMapView performSelector:@selector(updateTextView) withObject:nil afterDelay:kDefaultUpdateInterval];
98102
}
99103

100104
- (void)onCodeEditorBoundsChange:(NSNotification*)sender

0 commit comments

Comments
 (0)