2323static NSString * const DVTFontAndColorSourceTextSettingsChangedNotification = @" DVTFontAndColorSourceTextSettingsChangedNotification" ;// Unused
2424
2525#define kDefaultZoomLevel 0 .1f
26- #define kRightSidePadding 15 .0f
26+ #define kRightSidePadding 10 .0f
2727#define kDefaultShadowLevel 0 .1f
2828
2929@implementation SCXcodeMinimap
@@ -167,24 +167,27 @@ - (void)onDidFinishSetup:(NSNotification*)sender
167167 CGFloat width = editorTextView.bounds .size .width * kDefaultZoomLevel ;
168168
169169 NSRect frame = editorTextView.frame ;
170- frame.size .width -= width;
170+ frame.size .width -= ( width + kRightSidePadding ) ;
171171 [editorTextView setFrame: frame];
172172
173173 NSRect miniMapScrollViewFrame = NSMakeRect (editorContainerView.bounds .size .width - width - kRightSidePadding , 0 , width, editorScrollView.bounds .size .height );
174174 NSScrollView *miniMapScrollView = [[NSScrollView alloc ] initWithFrame: miniMapScrollViewFrame];
175175 [miniMapScrollView setWantsLayer: YES ];
176176 [miniMapScrollView setAutoresizingMask: NSViewMinXMargin | NSViewWidthSizable | NSViewHeightSizable];
177177 [miniMapScrollView setDrawsBackground: NO ];
178+ [miniMapScrollView setHorizontalScrollElasticity: NSScrollElasticityNone];
179+ [miniMapScrollView setVerticalScrollElasticity: NSScrollElasticityNone];
178180 [editorContainerView addSubview: miniMapScrollView];
179181 [miniMapScrollView release ];
180182
181183 objc_setAssociatedObject (editorScrollView, &kKeyMiniMapScrollView , miniMapScrollView, OBJC_ASSOCIATION_ASSIGN );
182184
183- NSTextView *miniMapTextView = [[NSTextView alloc ] initWithFrame: miniMapScrollView.bounds];
185+ SCTextView *miniMapTextView = [[SCTextView alloc ] initWithFrame: miniMapScrollView.bounds];
184186 [miniMapTextView setAutoresizingMask: NSViewMinXMargin | NSViewMaxXMargin | NSViewWidthSizable | NSViewHeightSizable];
185187 [miniMapTextView.textContainer setLineFragmentPadding: 0 .0f ];
186188 [miniMapTextView setSelectable: NO ];
187189 [miniMapTextView.layoutManager setDelegate: (id <NSLayoutManagerDelegate >)self ];
190+ [miniMapTextView setDelegate: self ];
188191
189192 objc_setAssociatedObject (miniMapTextView.layoutManager , &kKeyEditorTextView , editorTextView, OBJC_ASSOCIATION_ASSIGN );
190193
@@ -226,4 +229,30 @@ - (NSDictionary *)layoutManager:(NSLayoutManager *)layoutManager shouldUseTempor
226229 return [(id <NSLayoutManagerDelegate >)editorTextView layoutManager: layoutManager shouldUseTemporaryAttributes: attrs forDrawingToScreen: toScreen atCharacterIndex: charIndex effectiveRange: effectiveCharRange];
227230}
228231
232+ #pragma mark - SCTextViewDelegate
233+
234+ - (void )textView : (SCTextView *)textView goAtRelativePosition : (NSPoint )position
235+ {
236+ NSTextView *editorTextView = objc_getAssociatedObject (textView.layoutManager , &kKeyEditorTextView );
237+
238+ NSScrollView *editorScrollView = objc_getAssociatedObject (textView.textContainer , &kKeyEditorScrollView );
239+
240+ CGFloat documentHeight = [editorScrollView.documentView frame ].size .height ;
241+ CGSize boundsSize = editorScrollView.bounds .size ;
242+ CGFloat maxOffset = documentHeight - boundsSize.height ;
243+
244+ NSLog (@" Position Y = %f " ,position.y );
245+ NSLog (@" Document Frame Height = %f " , documentHeight);
246+ // NSLog(@"Bounds Height = %f", boundsHeight);
247+ NSLog (@" Max Offset = %f " , maxOffset);
248+
249+ CGFloat offset = floor (documentHeight * position.y - boundsSize.height /2 );
250+
251+ offset = MIN (MAX (0 , offset), maxOffset);
252+
253+ [editorTextView scrollRectToVisible: NSMakeRect (0 , offset, boundsSize.width, boundsSize.height)];
254+ // [editorScrollView.contentView scrollToPoint:NSMakePoint(0,offset)];
255+ }
256+
257+
229258@end
0 commit comments