Multi Input plugin: Correctly forward register and remove observer callbacks to the actual decoder in use

CQTexperiment
Christopher Snowhill 2021-12-26 02:01:53 -08:00
parent dfeca7aa97
commit 8d7cd6cc93
1 changed files with 7 additions and 2 deletions

View File

@ -126,18 +126,23 @@ NSArray * sortClassesByPriority(NSArray * theClasses)
} else { } else {
[cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", @(options), @"options", nil]]; [cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", @(options), @"options", nil]];
} }
if (theDecoder) {
[theDecoder addObserver:observer forKeyPath:keyPath options:options context:context];
}
} }
/* And this is currently called after the decoder is closed */ /* And this is currently called after the decoder is closed */
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath - (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath
{ {
for (NSDictionary *obsItem in cachedObservers) for (NSDictionary *obsItem in cachedObservers) {
{
if ([obsItem objectForKey:@"observer"] == observer && [keyPath isEqualToString:[obsItem objectForKey:@"keyPath"]]) { if ([obsItem objectForKey:@"observer"] == observer && [keyPath isEqualToString:[obsItem objectForKey:@"keyPath"]]) {
[cachedObservers removeObject:obsItem]; [cachedObservers removeObject:obsItem];
break; break;
} }
} }
if (theDecoder) {
[theDecoder removeObserver:observer forKeyPath:keyPath];
}
} }
@end @end