Skip to content
Snippets Groups Projects
Commit c5d46087 authored by George Nachman's avatar George Nachman
Browse files

Fix a bug where double-tap of a modifier didn't work unless a hotkey keypress...

Fix a bug where double-tap of a modifier didn't work unless a hotkey keypress was also defined. This revealed a bug in how weak references were used. isEqual: uses pointer equality by default, so it doesn't work on arrays of weak refs. I hacked around it by implementing isEqual: for the one class I care about.
parent 7f9aefbd
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -207,6 +207,20 @@ ITERM_WEAKLY_REFERENCEABLE
dispatch_release(doneGroup);
}
 
- (void)testRespondsToSelector {
iTerm2FakeObject *fakeObject = [[[iTerm2FakeObject alloc] init] autorelease];
fakeObject.number = 1234;
iTerm2FakeObject *ref = [fakeObject weakSelf];
// Method from subclass
XCTAssertTrue([ref respondsToSelector:@selector(number)]);
// Method from iTermWeakReference
XCTAssertTrue([ref respondsToSelector:@selector(weaklyReferencedObject)]);
// Method from superclass
XCTAssertTrue([ref respondsToSelector:@selector(isEqual:)]);
// Method that doesn't exist
XCTAssertFalse([ref respondsToSelector:@selector(testRespondsToSelector)]);
}
// This is a regression test. There was a bug that the weak reference did not properly remove itself
// from notification center. It was hard to see because it didn't happen in 10.11.
- (void)testReferenceRemovedFromNotificationCenter {
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ static const CGEventFlags kCGEventHotKeyModifierMask = (kCGEventFlagMaskAlphaShi
kCGEventFlagMaskControl);
 
 
@interface iTermBaseHotKey()<iTermEventTapObserver>
@interface iTermBaseHotKey()<iTermEventTapObserver, iTermWeaklyReferenceable>
 
// Override this to do a thing that needs to be done. `siblings` are other hotkeys (besides the one
// this call was made for) that have the same keypress.
Loading
Loading
@@ -54,6 +54,17 @@ ITERM_WEAKLY_REFERENCEABLE
NSStringFromClass([self class]), self, _shortcuts, @(self.hasModifierActivation), @(self.modifierActivation)];
}
 
// isEqual: uses pointer equality. Sigh. I really need to just use ARC.
- (BOOL)isEqual:(id)object {
if ([self respondsToSelector:@selector(weaklyReferencedObject)]) {
return [[(iTermWeakReference *)self weaklyReferencedObject] isEqual:object];
}
if ([object respondsToSelector:@selector(weaklyReferencedObject)]) {
return [self isEqual:[(iTermWeakReference *)object weaklyReferencedObject]];
}
return [super isEqual:object];
}
- (NSArray<iTermHotKeyDescriptor *> *)hotKeyDescriptors {
return [_shortcuts mapWithBlock:^id(iTermShortcut *anObject) {
return [anObject descriptor];
Loading
Loading
Loading
Loading
@@ -76,7 +76,14 @@
}];
if (!shortcuts.count) {
DLog(@"None of the shortcuts in profile %@ are assigned", profile[KEY_NAME]);
return;
// Check if there's double-tap of modifier enabled.
if (![profile[KEY_HOTKEY_ACTIVATE_WITH_MODIFIER] boolValue]) {
DLog(@"Double-tap of modifier not enabled either");
return;
} else {
DLog(@"Double-tap of modifier IS enabled");
}
}
iTermProfileHotKey *hotKey =
Loading
Loading
Loading
Loading
@@ -22,6 +22,7 @@ static OSSpinLock lock = OS_SPINLOCK_INIT;
}
 
- (instancetype)initWithObject:(id<iTermWeaklyReferenceable>)object {
assert([object conformsToProtocol:@protocol(iTermWeaklyReferenceable)]);
if (self) {
_object = object;
_class = [[object class] retain];
Loading
Loading
@@ -75,6 +76,14 @@ static OSSpinLock lock = OS_SPINLOCK_INIT;
 
#pragma mark - NSProxy
 
- (BOOL)respondsToSelector:(SEL)aSelector {
if ([NSStringFromSelector(aSelector) isEqualToString:NSStringFromSelector(@selector(weaklyReferencedObject))]) {
return YES;
} else {
return [super respondsToSelector:aSelector];
}
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
OSSpinLockLock(&lock);
id theObject = [_object retain];
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment