1212#import " SCXcodeMinimapSelectionView.h"
1313
1414#import " IDESourceCodeEditor+SCXcodeMinimap.h"
15- #import " IDEEditorDocument.h"
15+ #import " IDESourceCodeComparisonEditor.h"
16+ #import " IDESourceCodeDocument.h"
17+ #import " DVTFilePath.h"
1618
1719#import " DVTTextStorage.h"
1820#import " DVTLayoutManager+SCXcodeMinimap.h"
4042
4143#import " NSScroller+SCXcodeMinimap.h"
4244
45+ #import " IDEWorkspaceWindowController.h"
46+ #import " IDEWorkspaceTabController.h"
47+ #import " IDEEditorArea+SCXcodeMinimap.h"
48+ #import " IDEEditorModeViewController.h"
49+ #import " IDEEditorContext.h"
50+
4351typedef NS_ENUM (NSUInteger , SCXcodeMinimapAnnotationType) {
4452 SCXcodeMinimapAnnotationTypeUndefined,
4553 SCXcodeMinimapAnnotationTypeTypeWarning,
@@ -70,9 +78,13 @@ @interface SCXcodeMinimapView () < NSLayoutManagerDelegate,
7078 DBGBreakpointAnnotationProviderDelegate,
7179 IDEIssueAnnotationProviderDelegate,
7280 DVTLayoutManagerMinimapDelegate,
73- IDESourceCodeEditorSearchResultsDelegate >
81+ IDESourceCodeEditorSearchResultsDelegate,
82+ IDEEditorAreaMinimapDelegate >
7483
7584@property (nonatomic , weak ) IDESourceCodeEditor *editor;
85+
86+ @property (nonatomic , weak ) IDEEditorArea *editorArea;
87+
7688@property (nonatomic , strong ) DVTSourceTextView *editorTextView;
7789
7890@property (nonatomic , strong ) SCXcodeMinimapScrollView *scrollView;
@@ -120,7 +132,7 @@ - (instancetype)initWithEditor:(IDESourceCodeEditor *)editor
120132 [self .editor setSearchResultsDelegate: self ];
121133
122134 self.editorTextView = editor.textView ;
123-
135+
124136 [self setWantsLayer: YES ];
125137 [self setAutoresizingMask: NSViewMinXMargin | NSViewMinYMargin | NSViewWidthSizable | NSViewHeightSizable];
126138
@@ -137,7 +149,7 @@ - (instancetype)initWithEditor:(IDESourceCodeEditor *)editor
137149 [self .scrollView setVerticalScrollElasticity: NSScrollElasticityNone];
138150 [self addSubview: self .scrollView];
139151
140- self.textView = [[DVTSourceTextView alloc ] init ];
152+ self.textView = [[DVTSourceTextView alloc ] initWithFrame: CGRectZero ];
141153
142154 NSTextStorage *storage = self.editorTextView .textStorage ;
143155 [self .textView setTextStorage: storage];
@@ -191,7 +203,7 @@ - (instancetype)initWithEditor:(IDESourceCodeEditor *)editor
191203
192204 __weak typeof (self) weakSelf = self;
193205 [self .notificationObservers addObject: [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapShouldDisplayChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
194- [weakSelf setVisible: [[[ NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldDisplayKey] boolValue ] ];
206+ [weakSelf toggleVisibility ];
195207 }]];
196208
197209 [self .notificationObservers addObject: [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapZoomLevelChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
@@ -241,7 +253,7 @@ - (instancetype)initWithEditor:(IDESourceCodeEditor *)editor
241253 }]];
242254
243255 [self .notificationObservers addObject: [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapAutohideChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
244- [self tryShowing ];
256+ [self toggleVisibility ];
245257 }]];
246258
247259 [self .notificationObservers addObject: [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapThemeChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
@@ -268,23 +280,29 @@ - (void)viewDidMoveToWindow
268280 return ;
269281 }
270282
271- [self tryShowing ];
283+ self.editorArea = [self getEditorArea ];
284+ [self .editorArea setMinimapDelegate: self ];
285+
286+ [self toggleVisibility ];
272287}
273288
274- - (void )tryShowing
289+ - (void )toggleVisibility
275290{
291+ BOOL visible = [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldDisplayKey] boolValue ];
276292 BOOL shouldAutohide = [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldAutohideKey] boolValue ];
277293
278- if (shouldAutohide) {
279- NSRange visibleEditorRange = [self .editorTextView visibleCharacterRange ];
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 .editorTextView visibleCharacterRange ];
299+ if (NSEqualRanges (visibleEditorRange, NSMakeRange (0 , self.textView .string .length ))) {
300+ visible = NO ;
301+ }
282302 }
283303 }
284304
285- dispatch_async (dispatch_get_main_queue (), ^{
286- [self setVisible: [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldDisplayKey] boolValue ]];
287- });
305+ [self setVisible: visible];
288306}
289307
290308#pragma mark - Show/Hide
@@ -463,6 +481,13 @@ - (void)foldingManager:(DVTFoldingManager *)foldingManager didUnfoldRange:(NSRan
463481 [self updateOffset ];
464482}
465483
484+ #pragma mark - IDEEditorAreaMinimapDelegate
485+
486+ - (void )editorAreaDidChangeEditorMode : (IDEEditorArea *)editorArea
487+ {
488+ [self toggleVisibility ];
489+ }
490+
466491#pragma mark - DBGBreakpointAnnotationProviderDelegate
467492
468493- (void )breakpointAnnotationProviderDidChangeBreakpoints : (DBGBreakpointAnnotationProvider *)annotationProvider
@@ -693,9 +718,12 @@ - (void)updateTheme
693718- (void )updateSize
694719{
695720 CGFloat zoomLevel = [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapZoomLevelKey] doubleValue ];
696-
697721 CGFloat minimapWidth = (self.hidden ? 0 .0f : self.editor .containerView .bounds .size .width * zoomLevel);
698722
723+ if (CGRectGetWidth (self.bounds ) == minimapWidth) {
724+ return ;
725+ }
726+
699727 NSRect editorScrollViewFrame = self.editor .scrollView .frame ;
700728 editorScrollViewFrame.size .width = self.editor .scrollView .superview .frame .size .width - minimapWidth;
701729 self.editor .scrollView .frame = editorScrollViewFrame;
@@ -784,4 +812,57 @@ - (void)invalidateMinimap
784812 }
785813}
786814
815+ - (IDEEditorArea *)getEditorArea
816+ {
817+ IDEWorkspaceWindowController *windowController = [IDEWorkspaceWindowController workspaceWindowControllerForWindow: 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 ([superview isEqual: 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.editor isKindOfClass: [IDESourceCodeEditor class ]]) {
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 ([document isEqualTo: primaryDocument] || [document isEqualTo: alternateDocument] ||
851+ [document.filePath.fileName isEqualToString: primaryDocument.filePath.fileName] ||
852+ [document.filePath.fileName isEqualToString: alternateDocument.filePath.fileName]) {
853+ return tabController.editorArea ;
854+ }
855+
856+ } else if ([tabController.editorArea.primaryEditorContext.editor isKindOfClass: [IDESourceCodeComparisonEditor class ]]) {
857+
858+ IDESourceCodeComparisonEditor *editor = (IDESourceCodeComparisonEditor *)tabController.editorArea .primaryEditorContext .editor ;
859+
860+ if ([editor.primaryDocument isEqualTo: self .editor.sourceCodeDocument] || [editor.secondaryDocument isEqualTo: self .editor.sourceCodeDocument]) {
861+ return tabController.editorArea ;
862+ }
863+ }
864+
865+ return nil ;
866+ }
867+
787868@end
0 commit comments