Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the crash after leaving from snippet. #65

Merged
merged 1 commit into from
Feb 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.xcuserdatad
34 changes: 23 additions & 11 deletions Backlight/AAABacklight.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -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;

Expand All @@ -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];
}
Expand Down Expand Up @@ -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]) {
Expand Down