@@ -68,9 +68,8 @@ @implementation SCXcodeMinimapTheme
6868
6969@interface SCXcodeMinimapView () <NSLayoutManagerDelegate , DVTFoldingManagerDelegate, DBGBreakpointAnnotationProviderDelegate>
7070
71- @property (nonatomic , strong ) IDESourceCodeEditor *editor;
72- @property (nonatomic , strong ) NSScrollView *editorScrollView;
73- @property (nonatomic , strong ) DVTSourceTextView *editorTextView;
71+ @property (nonatomic , weak ) IDESourceCodeEditor *editor;
72+ @property (nonatomic , assign ) DVTSourceTextView *editorTextView;
7473
7574@property (nonatomic , strong ) NSScrollView *scrollView;
7675@property (nonatomic , strong ) DVTSourceTextView *textView;
@@ -92,47 +91,44 @@ @implementation SCXcodeMinimapView
9291- (void )dealloc
9392{
9493 [[NSNotificationCenter defaultCenter ] removeObserver: self ];
94+ [self .textView.textStorage removeLayoutManager: self .textView.layoutManager];
9595}
9696
97- - (instancetype )initWithFrame : ( NSRect ) frame editor : (IDESourceCodeEditor *)editor
97+ - (instancetype )initWithEditor : (IDESourceCodeEditor *)editor
9898{
99- if (self = [super initWithFrame: frame ])
99+ if (self = [super init ])
100100 {
101101 self.editor = editor;
102- self.editorScrollView = editor.scrollView ;
103102
104103 self.editorTextView = editor.textView ;
105104 [self .editorTextView.foldingManager setDelegate: self ];
106105
107106 [self setWantsLayer: YES ];
108- [self setAutoresizingMask: NSViewMinXMargin | NSViewHeightSizable];
107+ [self setAutoresizingMask: NSViewMinXMargin | NSViewMinYMargin | NSViewWidthSizable | NSViewHeightSizable];
109108
110109 self.scrollView = [[NSScrollView alloc ] initWithFrame: self .bounds];
111- [self .scrollView setAutoresizingMask: NSViewMinXMargin | NSViewHeightSizable];
110+ [self .scrollView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
112111 [self .scrollView setDrawsBackground: NO ];
112+ [self .scrollView setMinMagnification: 0 .0f ];
113+ [self .scrollView setMaxMagnification: 1 .0f ];
114+ [self .scrollView setAllowsMagnification: NO ];
113115
114116 [self .scrollView setHorizontalScrollElasticity: NSScrollElasticityNone];
115117 [self .scrollView setVerticalScrollElasticity: NSScrollElasticityNone];
116118 [self addSubview: self .scrollView];
117119
118- self.textView = [[DVTSourceTextView alloc ] initWithFrame: self .editorTextView.bounds ];
120+ self.textView = [[DVTSourceTextView alloc ] init ];
119121 [self .textView setTextStorage: self .editorTextView.textStorage];
120122 [self .textView setEditable: NO ];
121123 [self .textView setSelectable: NO ];
122124
123125 [self .scrollView setDocumentView: self .textView];
124126
125- [self .scrollView setAllowsMagnification: YES ];
126- [self .scrollView setMinMagnification: kDefaultZoomLevel ];
127- [self .scrollView setMaxMagnification: kDefaultZoomLevel ];
128- [self .scrollView setMagnification: kDefaultZoomLevel ];
129-
130127 self.selectionView = [[SCXcodeMinimapSelectionView alloc ] init ];
131128 [self .textView addSubview: _selectionView];
132129
133130 [self updateTheme ];
134131
135-
136132 BOOL shouldHighlightBreakpoints = [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldHighlightBreakpointsKey] boolValue ];
137133 if (shouldHighlightBreakpoints) {
138134
@@ -148,13 +144,20 @@ - (instancetype)initWithFrame:(NSRect)frame editor:(IDESourceCodeEditor *)editor
148144 }
149145
150146 BOOL shouldHideEditorVerticalScroller = [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldHideEditorScrollerKey] boolValue ];
151- [self .editorScrollView setHasVerticalScroller: !shouldHideEditorVerticalScroller];
147+ [self .editor.scrollView setHasVerticalScroller: !shouldHideEditorVerticalScroller];
148+
149+ // Notifications
152150
153151 __weak typeof (self) weakSelf = self;
154152 [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapShouldDisplayChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
155153 [weakSelf setVisible: [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldDisplayKey] boolValue ]];
156154 }];
157155
156+ [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapZoomLevelChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
157+ [weakSelf updateSize ];
158+ [weakSelf invalidateDisplayForVisibleRange ];
159+ }];
160+
158161 [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapHighlightBreakpointsChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
159162 [weakSelf invalidateDisplayForVisibleRange ];
160163 }];
@@ -180,7 +183,7 @@ - (instancetype)initWithFrame:(NSRect)frame editor:(IDESourceCodeEditor *)editor
180183 }];
181184
182185 [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapHideEditorScrollerChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
183- [weakSelf.editorScrollView setHasVerticalScroller: ![[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldHideEditorScrollerKey] boolValue ]];
186+ [weakSelf.editor.scrollView setHasVerticalScroller: ![[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldHideEditorScrollerKey] boolValue ]];
184187 }];
185188
186189 [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapThemeChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
@@ -201,20 +204,21 @@ - (instancetype)initWithFrame:(NSRect)frame editor:(IDESourceCodeEditor *)editor
201204 return self;
202205}
203206
207+ - (void )viewDidMoveToWindow
208+ {
209+ [self setVisible: [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldDisplayKey] boolValue ]];
210+ }
211+
204212#pragma mark - Show/Hide
205213
206214- (void )setVisible : (BOOL )visible
207215{
208- self.hidden = !visible;
216+ self.hidden = !visible;
209217
210- NSRect editorTextViewFrame = self.editorScrollView .frame ;
211- editorTextViewFrame.size .width = self.editorScrollView .superview .frame .size .width - (visible ? self.bounds .size .width : 0 .0f );
212- self.editorScrollView .frame = editorTextViewFrame;
218+ [self updateSize ];
219+ [self updateOffset ];
213220
214- if (visible) {
215- [self updateOffset ];
216- [self .textView.layoutManager setDelegate: self ];
217- }
221+ [self .textView.layoutManager setDelegate: (self .hidden ? nil : self )];
218222
219223 BOOL editorHighlightingEnabled = [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldHighlightEditorKey] boolValue ];
220224 if (editorHighlightingEnabled) {
@@ -361,24 +365,24 @@ - (void)updateOffset
361365 CGFloat editorTextHeight = CGRectGetHeight ([self .editorTextView.layoutManager usedRectForTextContainer: self .editorTextView.textContainer]);
362366 CGFloat minimapTextHeight = CGRectGetHeight ([self .textView.layoutManager usedRectForTextContainer: self .textView.textContainer]);
363367
364- CGFloat adjustedEditorContentHeight = editorTextHeight - CGRectGetHeight (self.editorScrollView .bounds );
368+ CGFloat adjustedEditorContentHeight = editorTextHeight - CGRectGetHeight (self.editor . scrollView .bounds );
365369 CGFloat adjustedMinimapContentHeight = minimapTextHeight - (CGRectGetHeight (self.scrollView .bounds ) * (1 / self.scrollView .magnification ));
366370
367- NSRect selectionViewFrame = NSMakeRect (0 , 0 , self.bounds .size .width * (1 / self.scrollView .magnification ), self.editorScrollView .visibleRect .size .height );
371+ NSRect selectionViewFrame = NSMakeRect (0 , 0 , self.bounds .size .width * (1 / self.scrollView .magnification ), self.editor . scrollView .visibleRect .size .height );
368372
369373 if (adjustedEditorContentHeight == 0 .0f ) {
370374 [self .selectionView setFrame: selectionViewFrame];
371375 return ;
372376 }
373377
374378 CGFloat ratio = (adjustedMinimapContentHeight / adjustedEditorContentHeight) * (1 / self.scrollView .magnification );
375- CGPoint offset = NSMakePoint (0 , MAX (0 , floorf (self.editorScrollView .contentView .bounds .origin .y * ratio * self.scrollView .magnification )));
379+ CGPoint offset = NSMakePoint (0 , MAX (0 , floorf (self.editor . scrollView .contentView .bounds .origin .y * ratio * self.scrollView .magnification )));
376380
377381 [self .scrollView.documentView scrollPoint: offset];
378382
379383
380384 ratio = (minimapTextHeight - self.selectionView .bounds .size .height ) / adjustedEditorContentHeight;
381- selectionViewFrame.origin .y = self.editorScrollView .contentView .bounds .origin .y * ratio;
385+ selectionViewFrame.origin .y = self.editor . scrollView .contentView .bounds .origin .y * ratio;
382386
383387 [self .selectionView setFrame: selectionViewFrame];
384388}
@@ -470,11 +474,36 @@ - (SCXcodeMinimapTheme *)minimapThemeWithTheme:(DVTFontAndColorTheme *)theme
470474 return minimapTheme;
471475}
472476
473- #pragma mark - Autoresizing
477+ #pragma mark - Sizing
478+
479+ - (void )updateSize
480+ {
481+ CGFloat zoomLevel = [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapZoomLevelKey] doubleValue ];
482+
483+ CGFloat minimapWidth = (self.hidden ? 0 .0f : self.editor .containerView .bounds .size .width * zoomLevel);
484+
485+ NSRect editorScrollViewFrame = self.editor .scrollView .frame ;
486+ editorScrollViewFrame.size .width = self.editor .scrollView .superview .frame .size .width - minimapWidth + 10 .0f ;
487+ self.editor .scrollView .frame = editorScrollViewFrame;
488+
489+ [self setFrame: NSMakeRect (CGRectGetMaxX (editorScrollViewFrame), 0 , minimapWidth, CGRectGetHeight (self .editor.containerView.bounds))];
490+
491+ CGRect frame = self.textView .bounds ;
492+ frame.size .width = CGRectGetWidth (self.editorTextView .bounds );
493+ [self .textView setFrame: frame];
494+
495+ CGFloat actualZoomLevel = CGRectGetWidth (self.bounds ) / CGRectGetWidth (self.editor .scrollView .bounds );
496+ [self .scrollView setMagnification: actualZoomLevel];
497+ }
474498
475499- (void )resizeWithOldSuperviewSize : (NSSize )oldSize
476500{
477501 [super resizeWithOldSuperviewSize: oldSize];
502+
503+ CGRect frame = self.textView .bounds ;
504+ frame.size .width = CGRectGetWidth (self.editorTextView .bounds );
505+ [self .textView setFrame: frame];
506+
478507 [self updateOffset ];
479508}
480509
0 commit comments