Skip to content

Commit

Permalink
Fix the crash after leaving from snippet.
Browse files Browse the repository at this point in the history
You can close a bunch of issues. :D
  • Loading branch information
wolfcon committed Feb 19, 2016
1 parent d95ac5c commit 5594adb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
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

0 comments on commit 5594adb

Please sign in to comment.