Skip to content

Commit 83fcc83

Browse files
committed
Various tweaks for #41
1 parent 9bafb65 commit 83fcc83

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

SCXcodeMinimap.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
1819E4291AA1FB5900C344F2 /* SCXcodeMinimapScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1819E4281AA1FB5900C344F2 /* SCXcodeMinimapScrollView.m */; };
1011
184C11861A740F97002A7C65 /* SCXcodeMinimapSelectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 184C11821A740F97002A7C65 /* SCXcodeMinimapSelectionView.m */; };
1112
184C11871A740F97002A7C65 /* SCXcodeMinimapView.m in Sources */ = {isa = PBXBuildFile; fileRef = 184C11841A740F97002A7C65 /* SCXcodeMinimapView.m */; };
1213
184C118F1A741136002A7C65 /* DVTFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 184C118E1A741136002A7C65 /* DVTFoundation.framework */; };
@@ -25,6 +26,8 @@
2526
/* Begin PBXFileReference section */
2627
180F0C651A98AE1500E97254 /* DVTAnnotationManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DVTAnnotationManager.h; sourceTree = "<group>"; };
2728
1812C3911A77A7CF00E2CFB3 /* IDESourceCodeDocument.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = IDESourceCodeDocument.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
29+
1819E4271AA1FB5900C344F2 /* SCXcodeMinimapScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SCXcodeMinimapScrollView.h; sourceTree = "<group>"; };
30+
1819E4281AA1FB5900C344F2 /* SCXcodeMinimapScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SCXcodeMinimapScrollView.m; sourceTree = "<group>"; };
2831
18269AD51A8F2F4300953B3D /* DVTFoldingManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DVTFoldingManager.h; sourceTree = "<group>"; };
2932
184407641A8F7B1900C530CF /* DVTTextDocumentLocation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DVTTextDocumentLocation.h; sourceTree = "<group>"; };
3033
184407651A8F7B3E00C530CF /* DVTDocumentLocation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DVTDocumentLocation.h; sourceTree = "<group>"; };
@@ -183,6 +186,8 @@
183186
18FE09C8170764E400118FEB /* SCXcodeMinimap.m */,
184187
184C11831A740F97002A7C65 /* SCXcodeMinimapView.h */,
185188
184C11841A740F97002A7C65 /* SCXcodeMinimapView.m */,
189+
1819E4271AA1FB5900C344F2 /* SCXcodeMinimapScrollView.h */,
190+
1819E4281AA1FB5900C344F2 /* SCXcodeMinimapScrollView.m */,
186191
184C11811A740F97002A7C65 /* SCXcodeMinimapSelectionView.h */,
187192
184C11821A740F97002A7C65 /* SCXcodeMinimapSelectionView.m */,
188193
18C2EA5A1A9C7F8A002CEB20 /* DBGBreakpointAnnotation+SCXcodeMinimap.h */,
@@ -270,6 +275,7 @@
270275
184C11861A740F97002A7C65 /* SCXcodeMinimapSelectionView.m in Sources */,
271276
184C11871A740F97002A7C65 /* SCXcodeMinimapView.m in Sources */,
272277
18C2EA5C1A9C7F8A002CEB20 /* DBGBreakpointAnnotation+SCXcodeMinimap.m in Sources */,
278+
1819E4291AA1FB5900C344F2 /* SCXcodeMinimapScrollView.m in Sources */,
273279
);
274280
runOnlyForDeploymentPostprocessing = 0;
275281
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// SCXcodeMinimapScrollView.h
3+
// SCXcodeMinimap
4+
//
5+
// Created by Stefan Ceriu on 28/02/2015.
6+
// Copyright (c) 2015 Stefan Ceriu. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
11+
@interface SCXcodeMinimapScrollView : NSScrollView
12+
13+
@end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// SCXcodeMinimapScrollView.m
3+
// SCXcodeMinimap
4+
//
5+
// Created by Stefan Ceriu on 28/02/2015.
6+
// Copyright (c) 2015 Stefan Ceriu. All rights reserved.
7+
//
8+
9+
#import "SCXcodeMinimapScrollView.h"
10+
11+
@implementation SCXcodeMinimapScrollView
12+
13+
- (void)scrollWheel:(NSEvent *)theEvent
14+
{
15+
// Disable the scroll wheel on top of the minimap
16+
}
17+
18+
@end

SCXcodeMinimap/SCXcodeMinimapView.m

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "SCXcodeMinimapView.h"
1010
#import "SCXcodeMinimap.h"
11+
#import "SCXcodeMinimapScrollView.h"
1112
#import "SCXcodeMinimapSelectionView.h"
1213

1314
#import "IDESourceCodeEditor.h"
@@ -72,7 +73,7 @@ @interface SCXcodeMinimapView () <NSLayoutManagerDelegate, DVTFoldingManagerDele
7273
@property (nonatomic, weak) IDESourceCodeEditor *editor;
7374
@property (nonatomic, strong) DVTSourceTextView *editorTextView;
7475

75-
@property (nonatomic, strong) NSScrollView *scrollView;
76+
@property (nonatomic, strong) SCXcodeMinimapScrollView *scrollView;
7677
@property (nonatomic, strong) DVTSourceTextView *textView;
7778
@property (nonatomic, strong) SCXcodeMinimapSelectionView *selectionView;
7879
@property (nonatomic, strong) IDESourceCodeDocument *document;
@@ -115,13 +116,15 @@ - (instancetype)initWithEditor:(IDESourceCodeEditor *)editor
115116
[self setWantsLayer:YES];
116117
[self setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin | NSViewWidthSizable | NSViewHeightSizable];
117118

118-
self.scrollView = [[NSScrollView alloc] initWithFrame:self.bounds];
119+
self.scrollView = [[SCXcodeMinimapScrollView alloc] initWithFrame:self.bounds];
119120
[self.scrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
120121
[self.scrollView setDrawsBackground:NO];
121122
[self.scrollView setMinMagnification:0.0f];
122123
[self.scrollView setMaxMagnification:1.0f];
123124
[self.scrollView setAllowsMagnification:NO];
124125

126+
[self.scrollView setHasHorizontalScroller:NO];
127+
[self.scrollView setHasVerticalScroller:NO];
125128
[self.scrollView setHorizontalScrollElasticity:NSScrollElasticityNone];
126129
[self.scrollView setVerticalScrollElasticity:NSScrollElasticityNone];
127130
[self addSubview:self.scrollView];
@@ -393,15 +396,16 @@ - (void)updateOffset
393396
CGFloat adjustedEditorContentHeight = editorTextHeight - CGRectGetHeight(self.editor.scrollView.bounds);
394397
CGFloat adjustedMinimapContentHeight = minimapTextHeight - (CGRectGetHeight(self.scrollView.bounds) * (1 / self.scrollView.magnification));
395398

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);
397400

398401
if(adjustedEditorContentHeight == 0.0f) {
399402
[self.selectionView setFrame:selectionViewFrame];
400403
return;
401404
}
402405

403406
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)));
405409

406410
[self.scrollView.documentView scrollPoint:offset];
407411

@@ -435,7 +439,16 @@ - (void)handleMouseEvent:(NSEvent *)theEvent
435439
NSPoint point = [self.textView convertPoint:theEvent.locationInWindow fromView:nil];
436440
NSUInteger characterIndex = [self.textView characterIndexForInsertionAtPoint:point];
437441
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];
439452
}
440453

441454
#pragma mark - Theme

0 commit comments

Comments
 (0)