@@ -70,7 +70,7 @@ @implementation SCXcodeMinimapTheme
7070@interface SCXcodeMinimapView () <NSLayoutManagerDelegate , DVTFoldingManagerDelegate, DBGBreakpointAnnotationProviderDelegate>
7171
7272@property (nonatomic , weak ) IDESourceCodeEditor *editor;
73- @property (nonatomic , assign ) DVTSourceTextView *editorTextView;
73+ @property (nonatomic , strong ) DVTSourceTextView *editorTextView;
7474
7575@property (nonatomic , strong ) NSScrollView *scrollView;
7676@property (nonatomic , strong ) DVTSourceTextView *textView;
@@ -87,15 +87,20 @@ @interface SCXcodeMinimapView () <NSLayoutManagerDelegate, DVTFoldingManagerDele
8787
8888@property (nonatomic , weak ) DBGBreakpointAnnotationProvider *breakpointAnnotationProvider;
8989
90+ @property (nonatomic , strong ) NSMutableArray *notificationObservers;
91+
9092@end
9193
9294@implementation SCXcodeMinimapView
9395
9496- (void )dealloc
95- {
96- [[NSNotificationCenter defaultCenter ] removeObserver: self ];
97+ {
98+ for (id observer in self.notificationObservers ) {
99+ [[NSNotificationCenter defaultCenter ] removeObserver: observer];
100+ }
101+
97102 [self .textView.textStorage removeLayoutManager: self .textView.layoutManager];
98- [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector ( invalidateDisplayForVisibleRange ) object :nil ];
103+ [self .breakpointAnnotationProvider setMinimapDelegate :nil ];
99104}
100105
101106- (instancetype )initWithEditor : (IDESourceCodeEditor *)editor
@@ -133,49 +138,54 @@ - (instancetype)initWithEditor:(IDESourceCodeEditor *)editor
133138
134139 [self updateTheme ];
135140
141+
142+ for (NSDictionary *providerDictionary in self.editorTextView .annotationManager .annotationProviders ) {
143+ if ([providerDictionary[@" annotationProviderObject" ] isKindOfClass: [DBGBreakpointAnnotationProvider class ]]) {
144+ self.breakpointAnnotationProvider = providerDictionary[@" annotationProviderObject" ];
145+ [self .breakpointAnnotationProvider setMinimapDelegate: self ];
146+ break ;
147+ }
148+ }
149+
136150 BOOL shouldHighlightBreakpoints = [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldHighlightBreakpointsKey] boolValue ];
137151 if (shouldHighlightBreakpoints) {
138-
139- for (NSDictionary *providerDictionary in self.editorTextView .annotationManager .annotationProviders ) {
140- if ([providerDictionary[@" annotationProviderObject" ] isKindOfClass: [DBGBreakpointAnnotationProvider class ]]) {
141- self.breakpointAnnotationProvider = providerDictionary[@" annotationProviderObject" ];
142- [self .breakpointAnnotationProvider setMinimapDelegate: self ];
143- break ;
144- }
145- }
146-
147152 self.shouldUpdateBreakpoints = YES ;
148153 [self invalidateDisplayForVisibleRange ];
149154 }
150155
156+
151157 BOOL shouldHideEditorVerticalScroller = [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldHideEditorScrollerKey] boolValue ];
152158 [self .editor.scrollView setHasVerticalScroller: !shouldHideEditorVerticalScroller];
153159
160+
154161 // Notifications
155162
163+ self.notificationObservers = [NSMutableArray array ];
164+
156165 __weak typeof (self) weakSelf = self;
157- [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapShouldDisplayChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
166+ [self .notificationObservers addObject: [ [NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapShouldDisplayChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
158167 [weakSelf setVisible: [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldDisplayKey] boolValue ]];
159- }];
168+ }]] ;
160169
161- [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapZoomLevelChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
170+ [self .notificationObservers addObject: [ [NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapZoomLevelChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
162171 [weakSelf updateSize ];
163172 [weakSelf invalidateDisplayForVisibleRange ];
164- }];
173+ }]] ;
165174
166- [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapHighlightBreakpointsChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
175+ [self .notificationObservers addObject: [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapHighlightBreakpointsChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
176+ weakSelf.shouldUpdateBreakpoints = YES ;
167177 [weakSelf invalidateDisplayForVisibleRange ];
168- }];
178+ }]] ;
169179
170- [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapHighlightCommentsChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
180+ [self .notificationObservers addObject: [ [NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapHighlightCommentsChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
171181 [weakSelf invalidateDisplayForVisibleRange ];
172- }];
182+ }]] ;
173183
174- [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapHighlightPreprocessorChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
184+ [self .notificationObservers addObject: [ [NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapHighlightPreprocessorChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
175185 [weakSelf invalidateDisplayForVisibleRange ];
176- }];
186+ }]] ;
177187
178- [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapHighlightEditorChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
188+ [self .notificationObservers addObject: [ [NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapHighlightEditorChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
179189
180190 BOOL editorHighlightingEnabled = [[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldHighlightEditorKey] boolValue ];
181191 if (editorHighlightingEnabled) {
@@ -185,25 +195,25 @@ - (instancetype)initWithEditor:(IDESourceCodeEditor *)editor
185195 }
186196
187197 [weakSelf invalidateDisplayForVisibleRange ];
188- }];
198+ }]] ;
189199
190- [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapHideEditorScrollerChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
200+ [self .notificationObservers addObject: [ [NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapHideEditorScrollerChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
191201 [weakSelf.editor.scrollView setHasVerticalScroller: ![[[NSUserDefaults standardUserDefaults ] objectForKey: SCXcodeMinimapShouldHideEditorScrollerKey] boolValue ]];
192- }];
202+ }]] ;
193203
194- [[NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapThemeChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
204+ [self .notificationObservers addObject: [ [NSNotificationCenter defaultCenter ] addObserverForName: SCXcodeMinimapThemeChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
195205 [weakSelf updateTheme ];
196- }];
197-
198- [[NSNotificationCenter defaultCenter ] addObserverForName: DVTFontAndColorSourceTextSettingsChangedNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
206+ }]] ;
207+
208+ [self .notificationObservers addObject: [ [NSNotificationCenter defaultCenter ] addObserverForName: DVTFontAndColorSourceTextSettingsChangedNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
199209 [weakSelf updateTheme ];
200- }];
210+ }]] ;
201211
202- [[NSNotificationCenter defaultCenter ] addObserverForName: IDESourceCodeEditorTextViewBoundsDidChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
212+ [self .notificationObservers addObject: [ [NSNotificationCenter defaultCenter ] addObserverForName: IDESourceCodeEditorTextViewBoundsDidChangeNotification object: nil queue: nil usingBlock: ^(NSNotification *note) {
203213 if ([note.object isEqual: weakSelf.editor]) {
204214 [weakSelf updateOffset ];
205215 }
206- }];
216+ }]] ;
207217 }
208218
209219 return self;
@@ -355,7 +365,8 @@ - (void)updateBreakpoints
355365
356366 for (DBGBreakpointAnnotation *breakpointAnnotation in self.breakpointAnnotationProvider .annotations ) {
357367 if (breakpointAnnotation.paragraphRange .location == lineNumber) {
358- [self .breakpointDictionaries addObject: @{kBreakpointRangeKey : [NSValue valueWithRange: lineRange], kBreakpointEnabledKey : @(breakpointAnnotation.enabled )}];
368+ [self .breakpointDictionaries addObject: @{kBreakpointRangeKey : [NSValue valueWithRange: lineRange],
369+ kBreakpointEnabledKey : @(breakpointAnnotation.enabled )}];
359370 }
360371 }
361372
0 commit comments