12
12
#import " SCXcodeMinimapSelectionView.h"
13
13
14
14
#import " IDESourceCodeEditor+SCXcodeMinimap.h"
15
- #import " IDEEditorDocument.h"
15
+ #import " IDESourceCodeComparisonEditor.h"
16
+ #import " IDESourceCodeDocument.h"
17
+ #import " DVTFilePath.h"
16
18
17
19
#import " DVTTextStorage.h"
18
20
#import " DVTLayoutManager+SCXcodeMinimap.h"
40
42
41
43
#import " NSScroller+SCXcodeMinimap.h"
42
44
45
+ #import " IDEWorkspaceWindowController.h"
46
+ #import " IDEWorkspaceTabController.h"
47
+ #import " IDEEditorArea+SCXcodeMinimap.h"
48
+ #import " IDEEditorModeViewController.h"
49
+ #import " IDEEditorContext.h"
50
+
43
51
typedef NS_ENUM (NSUInteger , SCXcodeMinimapAnnotationType) {
44
52
SCXcodeMinimapAnnotationTypeUndefined,
45
53
SCXcodeMinimapAnnotationTypeTypeWarning,
@@ -70,9 +78,13 @@ @interface SCXcodeMinimapView () < NSLayoutManagerDelegate,
70
78
DBGBreakpointAnnotationProviderDelegate,
71
79
IDEIssueAnnotationProviderDelegate,
72
80
DVTLayoutManagerMinimapDelegate,
73
- IDESourceCodeEditorSearchResultsDelegate >
81
+ IDESourceCodeEditorSearchResultsDelegate,
82
+ IDEEditorAreaMinimapDelegate >
74
83
75
84
@property (nonatomic ,weak ) IDESourceCodeEditor *editor;
85
+
86
+ @property (nonatomic ,weak ) IDEEditorArea *editorArea;
87
+
76
88
@property (nonatomic ,strong ) DVTSourceTextView *editorTextView;
77
89
78
90
@property (nonatomic ,strong ) SCXcodeMinimapScrollView *scrollView;
@@ -120,7 +132,7 @@ - (instancetype)initWithEditor:(IDESourceCodeEditor *)editor
120
132
[self .editorsetSearchResultsDelegate: self ];
121
133
122
134
self.editorTextView = editor.textView ;
123
-
135
+
124
136
[self setWantsLayer: YES ];
125
137
[self setAutoresizingMask: NSViewMinXMargin | NSViewMinYMargin | NSViewWidthSizable | NSViewHeightSizable];
126
138
@@ -137,7 +149,7 @@ - (instancetype)initWithEditor:(IDESourceCodeEditor *)editor
137
149
[self .scrollViewsetVerticalScrollElasticity: NSScrollElasticityNone];
138
150
[self addSubview: self .scrollView];
139
151
140
- self.textView = [[DVTSourceTextViewalloc ]init ];
152
+ self.textView = [[DVTSourceTextViewalloc ]initWithFrame: CGRectZero ];
141
153
142
154
NSTextStorage *storage = self.editorTextView .textStorage ;
143
155
[self .textViewsetTextStorage: storage];
@@ -191,7 +203,7 @@ - (instancetype)initWithEditor:(IDESourceCodeEditor *)editor
191
203
192
204
__weaktypeof (self) weakSelf = self;
193
205
[self .notificationObserversaddObject: [[NSNotificationCenter defaultCenter ]addObserverForName: SCXcodeMinimapShouldDisplayChangeNotificationobject: nil queue: nil usingBlock: ^(NSNotification *note) {
194
- [weakSelfsetVisible: [[[ NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldDisplayKey] boolValue ] ];
206
+ [weakSelftoggleVisibility ];
195
207
}]];
196
208
197
209
[self .notificationObserversaddObject: [[NSNotificationCenter defaultCenter ]addObserverForName: SCXcodeMinimapZoomLevelChangeNotificationobject: nil queue: nil usingBlock: ^(NSNotification *note) {
@@ -241,7 +253,7 @@ - (instancetype)initWithEditor:(IDESourceCodeEditor *)editor
241
253
}]];
242
254
243
255
[self .notificationObserversaddObject: [[NSNotificationCenter defaultCenter ]addObserverForName: SCXcodeMinimapAutohideChangeNotificationobject: nil queue: nil usingBlock: ^(NSNotification *note) {
244
- [self tryShowing ];
256
+ [self toggleVisibility ];
245
257
}]];
246
258
247
259
[self .notificationObserversaddObject: [[NSNotificationCenter defaultCenter ]addObserverForName: SCXcodeMinimapThemeChangeNotificationobject: nil queue: nil usingBlock: ^(NSNotification *note) {
@@ -268,23 +280,29 @@ - (void)viewDidMoveToWindow
268
280
return ;
269
281
}
270
282
271
- [self tryShowing ];
283
+ self.editorArea = [self getEditorArea ];
284
+ [self .editorAreasetMinimapDelegate: self ];
285
+
286
+ [self toggleVisibility ];
272
287
}
273
288
274
- - (void )tryShowing
289
+ - (void )toggleVisibility
275
290
{
291
+ BOOL visible = [[[NSUserDefaults standardUserDefaults ]objectForKey: SCXcodeMinimapShouldDisplayKey]boolValue ];
276
292
BOOL shouldAutohide = [[[NSUserDefaults standardUserDefaults ]objectForKey: SCXcodeMinimapShouldAutohideKey]boolValue ];
277
293
278
- if (shouldAutohide) {
279
- NSRange visibleEditorRange = [self .editorTextViewvisibleCharacterRange ];
280
- if (NSEqualRanges (visibleEditorRange,NSMakeRange (0 , self.textView .string .length ))) {
281
- return ;
294
+ if (shouldAutohide && visible) {
295
+ if (self.editorArea ==nil || self.editorArea .editorMode ) {
296
+ visible =NO ;
297
+ }else {
298
+ NSRange visibleEditorRange = [self .editorTextViewvisibleCharacterRange ];
299
+ if (NSEqualRanges (visibleEditorRange,NSMakeRange (0 , self.textView .string .length ))) {
300
+ visible =NO ;
301
+ }
282
302
}
283
303
}
284
304
285
- dispatch_async (dispatch_get_main_queue (), ^{
286
- [self setVisible: [[[NSUserDefaults standardUserDefaults ]objectForKey: SCXcodeMinimapShouldDisplayKey]boolValue ]];
287
- });
305
+ [self setVisible: visible];
288
306
}
289
307
290
308
#pragma mark - Show/Hide
@@ -463,6 +481,13 @@ - (void)foldingManager:(DVTFoldingManager *)foldingManager didUnfoldRange:(NSRan
463
481
[self updateOffset ];
464
482
}
465
483
484
+ #pragma mark - IDEEditorAreaMinimapDelegate
485
+
486
+ - (void )editorAreaDidChangeEditorMode : (IDEEditorArea *)editorArea
487
+ {
488
+ [self toggleVisibility ];
489
+ }
490
+
466
491
#pragma mark - DBGBreakpointAnnotationProviderDelegate
467
492
468
493
- (void )breakpointAnnotationProviderDidChangeBreakpoints : (DBGBreakpointAnnotationProvider *)annotationProvider
@@ -693,9 +718,12 @@ - (void)updateTheme
693
718
- (void )updateSize
694
719
{
695
720
CGFloat zoomLevel = [[[NSUserDefaults standardUserDefaults ]objectForKey: SCXcodeMinimapZoomLevelKey]doubleValue ];
696
-
697
721
CGFloat minimapWidth = (self.hidden ?0 .0f : self.editor .containerView .bounds .size .width * zoomLevel);
698
722
723
+ if (CGRectGetWidth (self.bounds ) == minimapWidth) {
724
+ return ;
725
+ }
726
+
699
727
NSRect editorScrollViewFrame = self.editor .scrollView .frame ;
700
728
editorScrollViewFrame.size .width = self.editor .scrollView .superview .frame .size .width - minimapWidth;
701
729
self.editor .scrollView .frame = editorScrollViewFrame;
@@ -784,4 +812,57 @@ - (void)invalidateMinimap
784
812
}
785
813
}
786
814
815
+ - (IDEEditorArea *)getEditorArea
816
+ {
817
+ IDEWorkspaceWindowController *windowController = [IDEWorkspaceWindowControllerworkspaceWindowControllerForWindow: self .window];
818
+ if (!windowController) {
819
+ return nil ;
820
+ }
821
+ IDEWorkspaceTabController *tabController =nil ;
822
+
823
+ for (IDEWorkspaceTabController *someTabController in windowController.workspaceTabControllers ) {
824
+
825
+ NSView *superview = self.superview ;
826
+ while (superview) {
827
+ if ([superviewisEqual: someTabController.view]) {
828
+ tabController = someTabController;
829
+ break ;
830
+ }
831
+
832
+ superview = superview.superview ;
833
+ }
834
+
835
+ if (tabController) {
836
+ break ;
837
+ }
838
+ }
839
+
840
+ if (!tabController) {
841
+ return nil ;
842
+ }
843
+
844
+ if ([tabController.editorArea.primaryEditorContext.editorisKindOfClass: [IDESourceCodeEditorclass ]]) {
845
+
846
+ IDEEditorDocument *document = self.editor .sourceCodeDocument ;
847
+ IDEEditorDocument *primaryDocument = tabController.editorArea .primaryEditorDocument ;
848
+ IDEEditorDocument *alternateDocument = tabController.editorArea .editorModeViewController .selectedAlternateEditorContext .editor .document ;
849
+
850
+ if ([documentisEqualTo: primaryDocument] || [documentisEqualTo: alternateDocument] ||
851
+ [document.filePath.fileNameisEqualToString: primaryDocument.filePath.fileName] ||
852
+ [document.filePath.fileNameisEqualToString: alternateDocument.filePath.fileName]) {
853
+ return tabController.editorArea ;
854
+ }
855
+
856
+ }else if ([tabController.editorArea.primaryEditorContext.editorisKindOfClass: [IDESourceCodeComparisonEditorclass ]]) {
857
+
858
+ IDESourceCodeComparisonEditor *editor = (IDESourceCodeComparisonEditor *)tabController.editorArea .primaryEditorContext .editor ;
859
+
860
+ if ([editor.primaryDocumentisEqualTo: self .editor.sourceCodeDocument] || [editor.secondaryDocumentisEqualTo: self .editor.sourceCodeDocument]) {
861
+ return tabController.editorArea ;
862
+ }
863
+ }
864
+
865
+ return nil ;
866
+ }
867
+
787
868
@end