diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..125ee7a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.xcuserdatad diff --git a/Backlight/AAABacklight.m b/Backlight/AAABacklight.m index 0b8bc70..7d9b1bc 100755 --- a/Backlight/AAABacklight.m +++ b/Backlight/AAABacklight.m @@ -194,12 +194,16 @@ - (void)adjustColor:(id)sender self.currentBacklightView.backlightColor = panel.color; self.backlightColor = panel.color; - if (self.textView) { + if (self.textView && + // keynote: avoid the crash From snippet + self.textView.superview != nil) { if ([self.textView.layoutManager temporaryAttribute:NSBackgroundColorAttributeName atCharacterIndex:self.currentLineRange.location effectiveRange:NULL]) { + [self.textView.layoutManager removeTemporaryAttribute:NSBackgroundColorAttributeName forCharacterRange:self.currentLineRange]; + [self.textView.layoutManager addTemporaryAttribute:NSBackgroundColorAttributeName value:self.backlightColor forCharacterRange:self.currentLineRange]; @@ -236,8 +240,9 @@ - (void)menuDidChange:(NSNotification *)notification - (void)backlightNotification:(NSNotification *)notification { id firstResponder = [[NSApp keyWindow] firstResponder]; + if (![firstResponder isKindOfClass:NSClassFromString(@"DVTSourceTextView")]) return; - + [self updateBacklightViewWithTextView:firstResponder]; } @@ -348,16 +353,19 @@ - (void)buildMenus - (void)updateBacklightViewWithTextView:(NSTextView *)textView { // Before changing the textView's instance, remove the old one's highlight. + id tempAttribute = [self.textView.layoutManager temporaryAttribute:NSBackgroundColorAttributeName + atCharacterIndex:self.currentLineRange.location + effectiveRange:NULL]; + if (self.textView != nil && self.textView != textView && self.currentMode == AAABacklightModeUnderneath && - [self.textView.layoutManager temporaryAttribute:NSBackgroundColorAttributeName - atCharacterIndex:self.currentLineRange.location - effectiveRange:NULL]) - { - [self.textView.layoutManager removeTemporaryAttribute:NSBackgroundColorAttributeName - forCharacterRange:self.currentLineRange]; - } + tempAttribute != nil && + // keynote: avoid the crash From snippet + self.textView.superview != nil) { + [self.textView.layoutManager removeTemporaryAttribute:NSBackgroundColorAttributeName + forCharacterRange:self.currentLineRange]; + } self.textView = textView; @@ -372,7 +380,9 @@ - (void)moveBacklightInTextView:(NSTextView *)textView [self.currentBacklightView removeFromSuperview]; if ([textView.layoutManager temporaryAttribute:NSBackgroundColorAttributeName atCharacterIndex:self.currentLineRange.location - effectiveRange:NULL]) { + effectiveRange:NULL] && + // keynote: avoid the crash From snippet + self.textView.superview != nil) { [textView.layoutManager removeTemporaryAttribute:NSBackgroundColorAttributeName forCharacterRange:self.currentLineRange]; } @@ -443,7 +453,9 @@ - (void)adjustBacklight [self moveBacklightInTextView:self.textView]; } else { [self.currentBacklightView removeFromSuperview]; - if (self.textView) { + if (self.textView && + // keynote: avoid the crash From snippet + self.textView.superview != nil) { if ([self.textView.layoutManager temporaryAttribute:NSBackgroundColorAttributeName atCharacterIndex:self.currentLineRange.location effectiveRange:NULL]) {