|
8 | 8 |
|
9 | 9 | #import "SCXcodeMinimapView.h" |
10 | 10 | #import "SCXcodeMinimap.h" |
| 11 | +#import "SCXcodeMinimapScrollView.h" |
11 | 12 | #import "SCXcodeMinimapSelectionView.h" |
12 | 13 |
|
13 | 14 | #import "IDESourceCodeEditor.h" |
@@ -72,7 +73,7 @@ @interface SCXcodeMinimapView () <NSLayoutManagerDelegate, DVTFoldingManagerDele |
72 | 73 | @property (nonatomic, weak) IDESourceCodeEditor *editor; |
73 | 74 | @property (nonatomic, strong) DVTSourceTextView *editorTextView; |
74 | 75 |
|
75 | | -@property (nonatomic, strong) NSScrollView *scrollView; |
| 76 | +@property (nonatomic, strong) SCXcodeMinimapScrollView *scrollView; |
76 | 77 | @property (nonatomic, strong) DVTSourceTextView *textView; |
77 | 78 | @property (nonatomic, strong) SCXcodeMinimapSelectionView *selectionView; |
78 | 79 | @property (nonatomic, strong) IDESourceCodeDocument *document; |
@@ -115,13 +116,15 @@ - (instancetype)initWithEditor:(IDESourceCodeEditor *)editor |
115 | 116 | [self setWantsLayer:YES]; |
116 | 117 | [self setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin | NSViewWidthSizable | NSViewHeightSizable]; |
117 | 118 |
|
118 | | - self.scrollView = [[NSScrollView alloc] initWithFrame:self.bounds]; |
| 119 | + self.scrollView = [[SCXcodeMinimapScrollView alloc] initWithFrame:self.bounds]; |
119 | 120 | [self.scrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
120 | 121 | [self.scrollView setDrawsBackground:NO]; |
121 | 122 | [self.scrollView setMinMagnification:0.0f]; |
122 | 123 | [self.scrollView setMaxMagnification:1.0f]; |
123 | 124 | [self.scrollView setAllowsMagnification:NO]; |
124 | 125 |
|
| 126 | + [self.scrollView setHasHorizontalScroller:NO]; |
| 127 | + [self.scrollView setHasVerticalScroller:NO]; |
125 | 128 | [self.scrollView setHorizontalScrollElasticity:NSScrollElasticityNone]; |
126 | 129 | [self.scrollView setVerticalScrollElasticity:NSScrollElasticityNone]; |
127 | 130 | [self addSubview:self.scrollView]; |
@@ -393,15 +396,16 @@ - (void)updateOffset |
393 | 396 | CGFloat adjustedEditorContentHeight = editorTextHeight - CGRectGetHeight(self.editor.scrollView.bounds); |
394 | 397 | CGFloat adjustedMinimapContentHeight = minimapTextHeight - (CGRectGetHeight(self.scrollView.bounds) * (1 / self.scrollView.magnification)); |
395 | 398 |
|
396 | | - NSRect selectionViewFrame = NSMakeRect(0, 0, self.bounds.size.width * (1 / self.scrollView.magnification), self.editor.scrollView.visibleRect.size.height); |
| 399 | + NSRect selectionViewFrame = NSMakeRect(0, 0, self.textView.bounds.size.width * (1 / self.scrollView.magnification), self.editor.scrollView.visibleRect.size.height); |
397 | 400 |
|
398 | 401 | if(adjustedEditorContentHeight == 0.0f) { |
399 | 402 | [self.selectionView setFrame:selectionViewFrame]; |
400 | 403 | return; |
401 | 404 | } |
402 | 405 |
|
403 | 406 | CGFloat ratio = (adjustedMinimapContentHeight / adjustedEditorContentHeight) * (1 / self.scrollView.magnification); |
404 | | - CGPoint offset = NSMakePoint(0, MAX(0, floorf(self.editor.scrollView.contentView.bounds.origin.y * ratio * self.scrollView.magnification))); |
| 407 | + CGPoint offset = NSMakePoint(self.editor.scrollView.contentView.bounds.origin.x, |
| 408 | + MAX(0, floorf(self.editor.scrollView.contentView.bounds.origin.y * ratio * self.scrollView.magnification))); |
405 | 409 |
|
406 | 410 | [self.scrollView.documentView scrollPoint:offset]; |
407 | 411 |
|
@@ -435,7 +439,16 @@ - (void)handleMouseEvent:(NSEvent *)theEvent |
435 | 439 | NSPoint point = [self.textView convertPoint:theEvent.locationInWindow fromView:nil]; |
436 | 440 | NSUInteger characterIndex = [self.textView characterIndexForInsertionAtPoint:point]; |
437 | 441 | NSRange lineRange = [self.textView.string lineRangeForRange:NSMakeRange(characterIndex, 0)]; |
438 | | - [self.editorTextView scrollRangeToVisible:lineRange animate:YES]; |
| 442 | + NSRange activeRange = [self.textView.layoutManager glyphRangeForCharacterRange:lineRange actualCharacterRange:NULL]; |
| 443 | + |
| 444 | + NSRect neededRect = [self.editorTextView.layoutManager boundingRectForGlyphRange:activeRange inTextContainer:self.editorTextView.textContainer]; |
| 445 | + neededRect.origin.y = MAX(0, neededRect.origin.y - CGRectGetHeight(self.editor.containerView.bounds) / 2); |
| 446 | + |
| 447 | + [NSAnimationContext beginGrouping]; |
| 448 | + [[NSAnimationContext currentContext] setDuration:0.25f]; |
| 449 | + [self.editor.scrollView.contentView.animator setBoundsOrigin:CGPointMake(0, neededRect.origin.y)]; |
| 450 | + [self.editor.scrollView reflectScrolledClipView:self.editor.scrollView.contentView]; |
| 451 | + [NSAnimationContext endGrouping]; |
439 | 452 | } |
440 | 453 |
|
441 | 454 | #pragma mark - Theme |
|
0 commit comments