diff --git a/Backlight/AAABacklight.m b/Backlight/AAABacklight.m index b78e514..cd37ae4 100755 --- a/Backlight/AAABacklight.m +++ b/Backlight/AAABacklight.m @@ -141,8 +141,6 @@ - (id)initWithBundle:(NSBundle *)plugin name:NSWindowDidResizeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backlightNotification:) name:NSWindowDidBecomeKeyNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endBacklightNotification:) - name:NSTextDidEndEditingNotification object:nil]; return self; } @@ -291,24 +289,6 @@ - (void)backlightNotification:(NSNotification *)notification [self updateBacklightViewWithTextView:firstResponder]; } -/** - * Respond to NSTextDidEndEditingNotification to remove the highlighted background color. - */ -- (void)endBacklightNotification:(NSNotification *)notification { - id firstResponder = [[NSApp keyWindow] firstResponder]; - if (![firstResponder isKindOfClass:NSClassFromString(@"DVTSourceTextView")]) return; - - if (self.textView != nil && - self.textView == firstResponder && - self.currentMode == AAABacklightModeUnderneath && - [self.textView.layoutManager temporaryAttribute:NSBackgroundColorAttributeName - atCharacterIndex:self.currentLineRange.location - effectiveRange:NULL]) { - [self.textView.layoutManager removeTemporaryAttribute:NSBackgroundColorAttributeName - forCharacterRange:self.currentLineRange]; - } -} - - (void)colorPanelWillClose:(NSNotification *)notification { NSColorPanel *panel = [NSColorPanel sharedColorPanel]; @@ -326,6 +306,18 @@ - (void)colorPanelWillClose:(NSNotification *)notification - (void)updateBacklightViewWithTextView:(NSTextView *)textView { + // Before changing the textView's instance, remove the old one's highlight. + 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]; + } + self.textView = textView; [self adjustBacklight];