Skip to content

Commit

Permalink
Merge pull request #39 from tyeen/fix#27
Browse files Browse the repository at this point in the history
Underneath mode: Remove the old highlight before switching textView.
  • Loading branch information
Aliaksandr Andrashuk committed Mar 30, 2015
2 parents e1e0e62 + 16f76e6 commit af6cf0a
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions Backlight/AAABacklight.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand Down

0 comments on commit af6cf0a

Please sign in to comment.