diff --git a/Backlight/AAABacklight.m b/Backlight/AAABacklight.m index 142d89f..b78e514 100755 --- a/Backlight/AAABacklight.m +++ b/Backlight/AAABacklight.m @@ -141,6 +141,8 @@ - (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; } @@ -289,6 +291,24 @@ - (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];