Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underneath mode: Remove the old highlight before switching textView. #39

Merged
merged 3 commits into from
Mar 30, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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