@@ -22,16 +22,15 @@ @implementation SCMiniMapView
22
22
23
23
- (id )initWithFrame : (NSRect )frame
24
24
{
25
- self = [super initWithFrame: frame];
26
- if (self)
25
+ if (self = [super initWithFrame: frame])
27
26
{
28
27
/* Configure ScrollView */
29
28
[self setWantsLayer: YES ];
30
29
[self setAutoresizingMask: NSViewMinXMargin | NSViewHeightSizable];
31
30
[self setDrawsBackground: NO ];
32
31
[self setHorizontalScrollElasticity: NSScrollElasticityNone];
33
32
[self setVerticalScrollElasticity: NSScrollElasticityNone];
34
-
33
+
35
34
/* Subscribe to show/hide notifications */
36
35
[[NSNotificationCenter defaultCenter ] addObserver: self
37
36
selector: @selector (show )
@@ -65,7 +64,7 @@ - (NSTextView *)textView
65
64
[_textView setBackgroundColor: [NSColor clearColor ]];
66
65
67
66
[_textView.textContainer setLineFragmentPadding: 0 .0f ];
68
-
67
+
69
68
[_textView.layoutManager setDelegate: self ];
70
69
71
70
[_textView setAllowsUndo: NO ];
@@ -78,7 +77,7 @@ - (NSTextView *)textView
78
77
[_textView setAutomaticTextReplacementEnabled: NO ];
79
78
[_textView setContinuousSpellCheckingEnabled: NO ];
80
79
[_textView setDisplaysLinkToolTips: NO ];
81
- [_textView setEditable: NO ];
80
+ [_textView setEditable: NO ];
82
81
[_textView setRichText: YES ];
83
82
[_textView setSelectable: NO ];
84
83
@@ -103,7 +102,7 @@ - (SCSelectionView *)selectionView
103
102
104
103
- (NSFont *)font
105
104
{
106
- if (_font == nil ) {
105
+ if (_font == nil ) {
107
106
_font = [NSFont fontWithName: @" Menlo" size: 11 * kDefaultZoomLevel ];
108
107
109
108
Class DVTFontAndColorThemeClass = NSClassFromString (@" DVTFontAndColorTheme" );
@@ -135,7 +134,7 @@ - (NSColor *)backgroundColor
135
134
}
136
135
}
137
136
}
138
-
137
+
139
138
return _backgroundColor;
140
139
}
141
140
@@ -144,7 +143,7 @@ - (NSColor *)backgroundColor
144
143
- (void )show
145
144
{
146
145
self.hidden = NO ;
147
-
146
+
148
147
NSRect editorTextViewFrame = self.editorScrollView .frame ;
149
148
editorTextViewFrame.size .width = self.editorScrollView .superview .frame .size .width - self.bounds .size .width ;
150
149
self.editorScrollView .frame = editorTextViewFrame;
@@ -156,7 +155,7 @@ - (void)show
156
155
- (void )hide
157
156
{
158
157
self.hidden = YES ;
159
-
158
+
160
159
NSRect editorTextViewFrame = self.editorScrollView .frame ;
161
160
editorTextViewFrame.size .width = self.editorScrollView .superview .frame .size .width ;
162
161
self.editorScrollView .frame = editorTextViewFrame;
@@ -178,24 +177,26 @@ - (void)updateTextView
178
177
if ([self isHidden ]) {
179
178
return ;
180
179
}
181
-
180
+
182
181
NSMutableAttributedString *mutableAttributedString = [self .editorTextView.textStorage mutableCopy ];
183
-
182
+
184
183
if (mutableAttributedString == nil ) {
185
184
return ;
186
185
}
187
186
188
- __block NSMutableParagraphStyle *style;
189
187
[mutableAttributedString enumerateAttribute: NSParagraphStyleAttributeName
190
188
inRange: NSMakeRange (0 , mutableAttributedString.length)
191
189
options: 0
192
190
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];
194
196
}];
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
+
199
200
[self .textView.textStorage setAttributedString: mutableAttributedString];
200
201
}
201
202
@@ -210,22 +211,22 @@ - (void)updateSelectionView
210
211
if ([self isHidden ]) {
211
212
return ;
212
213
}
213
-
214
+
214
215
NSRect selectionViewFrame = NSMakeRect (0 ,
215
216
0 ,
216
217
self.bounds .size .width ,
217
218
self.editorScrollView .visibleRect .size .height * kDefaultZoomLevel );
218
-
219
-
219
+
220
+
220
221
CGFloat editorContentHeight = [self .editorScrollView.documentView frame ].size .height - self.editorScrollView .bounds .size .height ;
221
-
222
+
222
223
if (editorContentHeight == 0 ) {
223
224
selectionViewFrame.origin .y = 0 ;
224
225
}
225
226
else {
226
227
CGFloat ratio = ([self .documentView frame ].size .height - self.bounds .size .height ) / editorContentHeight;
227
228
[self .contentView scrollToPoint: NSMakePoint (0 , floorf (self .editorScrollView.contentView.bounds.origin.y * ratio))];
228
-
229
+
229
230
CGFloat textHeight = [self .textView.layoutManager usedRectForTextContainer: self .textView.textContainer].size .height ;
230
231
ratio = (textHeight - self.selectionView .bounds .size .height ) / editorContentHeight;
231
232
selectionViewFrame.origin .y = self.editorScrollView .contentView .bounds .origin .y * ratio;
@@ -300,11 +301,11 @@ - (void)goAtRelativePosition:(NSPoint)position
300
301
CGFloat documentHeight = [self .editorScrollView.documentView frame ].size .height ;
301
302
CGSize boundsSize = self.editorScrollView .bounds .size ;
302
303
CGFloat maxOffset = documentHeight - boundsSize.height ;
303
-
304
+
304
305
CGFloat offset = floor (documentHeight * position.y - boundsSize.height /2 );
305
-
306
+
306
307
offset = MIN (MAX (0 , offset), maxOffset);
307
-
308
+
308
309
[self .editorTextView scrollRectToVisible: NSMakeRect (0 , offset, boundsSize.width, boundsSize.height)];
309
310
}
310
311
0 commit comments