From 524f587a81299d88f237a457f76dbcd8d5b910ef Mon Sep 17 00:00:00 2001 From: tyeen Date: Wed, 25 Mar 2015 23:39:40 +0900 Subject: [PATCH 1/3] Underneath mode: Remove the old highlight before switching textView. To make sure the old one doesn't remain there. --- Backlight/AAABacklight.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Backlight/AAABacklight.m b/Backlight/AAABacklight.m index b78e514..eabd088 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; } @@ -326,6 +324,17 @@ - (void)colorPanelWillClose:(NSNotification *)notification - (void)updateBacklightViewWithTextView:(NSTextView *)textView { + // Before changing the textView's instance, remove the old one's highlight. + if (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]; From fdf396305c996c17c808748be7af4343a87a15fb Mon Sep 17 00:00:00 2001 From: tyeen Date: Thu, 26 Mar 2015 00:20:39 +0900 Subject: [PATCH 2/3] Delete the unused method. --- Backlight/AAABacklight.m | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/Backlight/AAABacklight.m b/Backlight/AAABacklight.m index eabd088..181da90 100755 --- a/Backlight/AAABacklight.m +++ b/Backlight/AAABacklight.m @@ -289,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]; From 16f76e69fe28ca126eaef6913aa593a655e09d79 Mon Sep 17 00:00:00 2001 From: tyeen Date: Thu, 26 Mar 2015 00:24:08 +0900 Subject: [PATCH 3/3] Check for nil pointer. --- Backlight/AAABacklight.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Backlight/AAABacklight.m b/Backlight/AAABacklight.m index 181da90..cd37ae4 100755 --- a/Backlight/AAABacklight.m +++ b/Backlight/AAABacklight.m @@ -307,7 +307,8 @@ - (void)colorPanelWillClose:(NSNotification *)notification - (void)updateBacklightViewWithTextView:(NSTextView *)textView { // Before changing the textView's instance, remove the old one's highlight. - if (self.textView != textView && + if (self.textView != nil && + self.textView != textView && self.currentMode == AAABacklightModeUnderneath && [self.textView.layoutManager temporaryAttribute:NSBackgroundColorAttributeName atCharacterIndex:self.currentLineRange.location