Skip to content

Commit c09dfd7

Browse files
committed
Fixes for #17 (incomplete)
1 parent 038c726 commit c09dfd7

File tree

3 files changed

+41
-44
lines changed

3 files changed

+41
-44
lines changed

SCXcodeMinimap/SCMiniMapView.m

+26-25
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ @implementation SCMiniMapView
2222

2323
- (id)initWithFrame:(NSRect)frame
2424
{
25-
self = [super initWithFrame:frame];
26-
if (self)
25+
if (self = [super initWithFrame:frame])
2726
{
2827
/* Configure ScrollView */
2928
[self setWantsLayer:YES];
3029
[self setAutoresizingMask: NSViewMinXMargin | NSViewHeightSizable];
3130
[self setDrawsBackground:NO];
3231
[self setHorizontalScrollElasticity:NSScrollElasticityNone];
3332
[self setVerticalScrollElasticity:NSScrollElasticityNone];
34-
33+
3534
/* Subscribe to show/hide notifications */
3635
[[NSNotificationCenter defaultCenter] addObserver:self
3736
selector:@selector(show)
@@ -65,7 +64,7 @@ - (NSTextView *)textView
6564
[_textView setBackgroundColor:[NSColor clearColor]];
6665

6766
[_textView.textContainer setLineFragmentPadding:0.0f];
68-
67+
6968
[_textView.layoutManager setDelegate:self];
7069

7170
[_textView setAllowsUndo:NO];
@@ -78,7 +77,7 @@ - (NSTextView *)textView
7877
[_textView setAutomaticTextReplacementEnabled:NO];
7978
[_textView setContinuousSpellCheckingEnabled:NO];
8079
[_textView setDisplaysLinkToolTips:NO];
81-
[_textView setEditable:NO];
80+
[_textView setEditable:NO];
8281
[_textView setRichText:YES];
8382
[_textView setSelectable:NO];
8483

@@ -103,7 +102,7 @@ - (SCSelectionView *)selectionView
103102

104103
- (NSFont *)font
105104
{
106-
if(_font == nil) {
105+
if(_font == nil) {
107106
_font = [NSFont fontWithName:@"Menlo" size:11 * kDefaultZoomLevel];
108107

109108
Class DVTFontAndColorThemeClass = NSClassFromString(@"DVTFontAndColorTheme");
@@ -135,7 +134,7 @@ - (NSColor *)backgroundColor
135134
}
136135
}
137136
}
138-
137+
139138
return _backgroundColor;
140139
}
141140

@@ -144,7 +143,7 @@ - (NSColor *)backgroundColor
144143
- (void)show
145144
{
146145
self.hidden = NO;
147-
146+
148147
NSRect editorTextViewFrame = self.editorScrollView.frame;
149148
editorTextViewFrame.size.width = self.editorScrollView.superview.frame.size.width - self.bounds.size.width;
150149
self.editorScrollView.frame = editorTextViewFrame;
@@ -156,7 +155,7 @@ - (void)show
156155
- (void)hide
157156
{
158157
self.hidden = YES;
159-
158+
160159
NSRect editorTextViewFrame = self.editorScrollView.frame;
161160
editorTextViewFrame.size.width = self.editorScrollView.superview.frame.size.width;
162161
self.editorScrollView.frame = editorTextViewFrame;
@@ -178,24 +177,26 @@ - (void)updateTextView
178177
if ([self isHidden]) {
179178
return;
180179
}
181-
180+
182181
NSMutableAttributedString *mutableAttributedString = [self.editorTextView.textStorage mutableCopy];
183-
182+
184183
if(mutableAttributedString == nil) {
185184
return;
186185
}
187186

188-
__block NSMutableParagraphStyle *style;
189187
[mutableAttributedString enumerateAttribute:NSParagraphStyleAttributeName
190188
inRange:NSMakeRange(0, mutableAttributedString.length)
191189
options:0
192190
usingBlock:^(id value, NSRange range, BOOL *stop) {
193-
style = [value mutableCopy];
191+
192+
NSMutableParagraphStyle *style = [value mutableCopy];
193+
[style setTabStops:@[]];
194+
[style setDefaultTabInterval:style.defaultTabInterval * kDefaultZoomLevel];
195+
[mutableAttributedString addAttributes:@{NSParagraphStyleAttributeName:style} range:range];
194196
}];
195-
[style setTabStops:@[]];
196-
[style setDefaultTabInterval:style.defaultTabInterval * kDefaultZoomLevel];
197-
198-
[mutableAttributedString setAttributes:@{NSFontAttributeName: self.font, NSParagraphStyleAttributeName : style} range:NSMakeRange(0, mutableAttributedString.length)];
197+
198+
[mutableAttributedString setAttributes:@{NSFontAttributeName: self.font} range:NSMakeRange(0, mutableAttributedString.length)];
199+
199200
[self.textView.textStorage setAttributedString:mutableAttributedString];
200201
}
201202

@@ -210,22 +211,22 @@ - (void)updateSelectionView
210211
if ([self isHidden]) {
211212
return;
212213
}
213-
214+
214215
NSRect selectionViewFrame = NSMakeRect(0,
215216
0,
216217
self.bounds.size.width,
217218
self.editorScrollView.visibleRect.size.height * kDefaultZoomLevel);
218-
219-
219+
220+
220221
CGFloat editorContentHeight = [self.editorScrollView.documentView frame].size.height - self.editorScrollView.bounds.size.height;
221-
222+
222223
if(editorContentHeight == 0) {
223224
selectionViewFrame.origin.y = 0;
224225
}
225226
else {
226227
CGFloat ratio = ([self.documentView frame].size.height - self.bounds.size.height) / editorContentHeight;
227228
[self.contentView scrollToPoint:NSMakePoint(0, floorf(self.editorScrollView.contentView.bounds.origin.y * ratio))];
228-
229+
229230
CGFloat textHeight = [self.textView.layoutManager usedRectForTextContainer:self.textView.textContainer].size.height;
230231
ratio = (textHeight - self.selectionView.bounds.size.height) / editorContentHeight;
231232
selectionViewFrame.origin.y = self.editorScrollView.contentView.bounds.origin.y * ratio;
@@ -300,11 +301,11 @@ - (void)goAtRelativePosition:(NSPoint)position
300301
CGFloat documentHeight = [self.editorScrollView.documentView frame].size.height;
301302
CGSize boundsSize = self.editorScrollView.bounds.size;
302303
CGFloat maxOffset = documentHeight - boundsSize.height;
303-
304+
304305
CGFloat offset = floor(documentHeight * position.y - boundsSize.height/2);
305-
306+
306307
offset = MIN(MAX(0, offset), maxOffset);
307-
308+
308309
[self.editorTextView scrollRectToVisible:NSMakeRect(0, offset, boundsSize.width, boundsSize.height)];
309310
}
310311

SCXcodeMinimap/SCSelectionView.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ - (NSColor *)selectionColor
3232
NSColor *backgroundColor = [[theme performSelector:@selector(sourceTextBackgroundColor)] colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
3333

3434
if(self.shouldInverseColors) {
35-
35+
3636
_selectionColor = [NSColor colorWithCalibratedRed:(1.0f - [backgroundColor redComponent])
3737
green:(1.0f - [backgroundColor greenComponent])
3838
blue:(1.0f - [backgroundColor blueComponent])

SCXcodeMinimap/SCXcodeMinimap.m

+14-18
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ - (void)createMenuItem
5353
}
5454

5555
NSMenuItem *miniMapItem = [[NSMenuItem alloc] initWithTitle:@""
56-
action:NULL
57-
keyEquivalent:@"M"];
56+
action:NULL
57+
keyEquivalent:@"M"];
5858
[miniMapItem setKeyEquivalentModifierMask:NSControlKeyMask | NSShiftKeyMask];
5959

6060
miniMapItem.target = self;
6161

6262
[editMenuItem.submenu insertItem:[NSMenuItem separatorItem]
63-
atIndex:[editMenuItem.submenu numberOfItems]];
63+
atIndex:[editMenuItem.submenu numberOfItems]];
6464
[editMenuItem.submenu insertItem:miniMapItem
65-
atIndex:[editMenuItem.submenu numberOfItems]];
66-
65+
atIndex:[editMenuItem.submenu numberOfItems]];
66+
6767
if ([[NSUserDefaults standardUserDefaults] boolForKey:SCXodeMinimapIsInitiallyHidden]) {
6868
[self hideMiniMap:miniMapItem];
6969
}
@@ -75,33 +75,29 @@ - (void)createMenuItem
7575
- (void)hideMiniMap:(NSMenuItem *)sender
7676
{
7777
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:SCXodeMinimapIsInitiallyHidden];
78-
78+
7979
[sender setTitle:@"Show MiniMap"];
8080
[sender setAction:@selector(showMiniMap:)];
81-
81+
8282
[[NSNotificationCenter defaultCenter] postNotificationName:SCXodeMinimapWantsToBeHiddenNotification object:nil];
8383
}
8484

8585
- (void)showMiniMap:(NSMenuItem *)sender
8686
{
8787
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:SCXodeMinimapIsInitiallyHidden];
88-
88+
8989
[sender setTitle:@"Hide MiniMap"];
9090
[sender setAction:@selector(hideMiniMap:)];
91-
91+
9292
[[NSNotificationCenter defaultCenter] postNotificationName:SCXodeMinimapWantsToBeShownNotification object:nil];
9393
}
9494

9595
- (void)onDocumentDidChange:(NSNotification*)sender
9696
{
97-
if ([[[sender object] class] isSubclassOfClass:[NSDocument class]])
98-
{
9997
SCMiniMapView *miniMapView = objc_getAssociatedObject([sender object], &kKeyMiniMapView);
10098
[miniMapView updateTextView];
10199
}
102100

103-
}
104-
105101
- (void)onCodeEditorBoundsChange:(NSNotification*)sender
106102
{
107103
if(![sender.object respondsToSelector:@selector(scrollView)]) {
@@ -131,32 +127,32 @@ - (void)onDidFinishSetup:(NSNotification*)sender
131127
NSLog(@"Could not fetch editor document");
132128
return;
133129
}
134-
130+
135131
/* Get Editor Components */
136132
NSDocument *editorDocument = [[sender object] performSelector:@selector(sourceCodeDocument)];
137133
NSView *editorContainerView = [[sender object] performSelector:@selector(containerView)];
138134
NSScrollView *editorScrollView = [[sender object] performSelector:@selector(scrollView)];
139135
NSTextView *editorTextView = [[sender object] performSelector:@selector(textView)];
140136

141137
[editorTextView setAutoresizingMask:NSViewMinXMargin | NSViewMaxXMargin | NSViewWidthSizable | NSViewHeightSizable];
142-
138+
143139
/* Create Mini Map */
144140
CGFloat width = editorTextView.bounds.size.width * kDefaultZoomLevel;
145141

146142
NSRect miniMapScrollViewFrame = NSMakeRect(editorContainerView.bounds.size.width - width,
147143
0,
148144
width,
149145
editorScrollView.bounds.size.height);
150-
146+
151147
SCMiniMapView *miniMapView = [[SCMiniMapView alloc] initWithFrame:miniMapScrollViewFrame];
152148
miniMapView.editorScrollView = editorScrollView;
153149
miniMapView.editorTextView = editorTextView;
154150
[editorContainerView addSubview:miniMapView];
155-
151+
156152
/* Setup Associated Objects */
157153
objc_setAssociatedObject(editorScrollView, &kKeyMiniMapView, miniMapView, OBJC_ASSOCIATION_ASSIGN);
158154
objc_setAssociatedObject(editorDocument, &kKeyMiniMapView, miniMapView, OBJC_ASSOCIATION_ASSIGN);
159-
155+
160156
if ([[NSUserDefaults standardUserDefaults] boolForKey:SCXodeMinimapIsInitiallyHidden]) {
161157
[miniMapView hide];
162158
}

0 commit comments

Comments
 (0)