remane textBackground to textBackgroundColor and use that for restoring highlit characters, without resding/storing such attribute

This commit is contained in:
Riccardo Mottola 2021-11-23 01:09:50 +01:00
parent 1749847eac
commit a0856faf21
2 changed files with 11 additions and 24 deletions

View file

@ -73,15 +73,15 @@
NSColor *highlightColor; NSColor *highlightColor;
NSColor *backgroundColor; NSColor *backgroundColor;
NSColor *readOnlyColor; NSColor *readOnlyColor;
NSColor *textBackground; NSColor *textBackgroundColor;
// location of the highlighted delimiter characters // location of the highlighted delimiter characters
// NSNotFound means not set // NSNotFound means not set
NSUInteger highlighted_chars[2]; NSUInteger highlighted_chars[2];
// the stored color and font attributes of the highlit character, so // the stored font attributes of the highlit character, so
// that they can be restored later on when the character is un-highlit // that they can be restored later on when the character is un-highlit
NSColor *previousBGColor; // A pair is assumed to have the same attributes
NSColor *previousFont; NSColor *previousFont;
// This is used to protect that -textViewDidChangeSelection: invocations // This is used to protect that -textViewDidChangeSelection: invocations

View file

@ -136,7 +136,7 @@
RELEASE(lm); RELEASE(lm);
ev = [[PCEditorView alloc] initWithFrame:fr textContainer:tc]; ev = [[PCEditorView alloc] initWithFrame:fr textContainer:tc];
[ev setBackgroundColor:textBackground]; [ev setBackgroundColor:textBackgroundColor];
[ev setTextColor:textColor]; [ev setTextColor:textColor];
[ev setEditor:self]; [ev setEditor:self];
if (_highlightSyntax) if (_highlightSyntax)
@ -218,8 +218,7 @@
ASSIGN(textColor, [NSColor blackColor]); ASSIGN(textColor, [NSColor blackColor]);
ASSIGN(backgroundColor, [NSColor whiteColor]); ASSIGN(backgroundColor, [NSColor whiteColor]);
ASSIGN(readOnlyColor, [NSColor lightGrayColor]); ASSIGN(readOnlyColor, [NSColor lightGrayColor]);
previousBGColor = nil;
previousFont = nil; previousFont = nil;
highlighted_chars[0] = NSNotFound; highlighted_chars[0] = NSNotFound;
@ -306,17 +305,17 @@
NSColor *col; NSColor *col;
col = [prefs colorForKey:EditorBackgroundColor defaultValue:backgroundColor]; col = [prefs colorForKey:EditorBackgroundColor defaultValue:backgroundColor];
textBackground = col; textBackgroundColor = col;
} }
else else
{ {
textBackground = readOnlyColor; textBackgroundColor = readOnlyColor;
} }
textColor = [prefs colorForKey:EditorForegroundColor defaultValue:textColor]; textColor = [prefs colorForKey:EditorForegroundColor defaultValue:textColor];
[attributes setObject:font forKey:NSFontAttributeName]; [attributes setObject:font forKey:NSFontAttributeName];
[attributes setObject:textBackground forKey:NSBackgroundColorAttributeName]; [attributes setObject:textBackgroundColor forKey:NSBackgroundColorAttributeName];
[attributes setObject:textColor forKey:NSForegroundColorAttributeName]; [attributes setObject:textColor forKey:NSForegroundColorAttributeName];
[attributes setObject:[NSNumber numberWithInt: 0] // disable ligatures [attributes setObject:[NSNumber numberWithInt: 0] // disable ligatures
forKey:NSLigatureAttributeName]; forKey:NSLigatureAttributeName];
@ -1389,17 +1388,9 @@ NSUInteger FindDelimiterInString(NSString * string,
[textStorage removeAttribute:NSFontAttributeName range:r]; [textStorage removeAttribute:NSFontAttributeName range:r];
} }
if (previousBGColor != nil) [textStorage addAttribute:NSBackgroundColorAttributeName
{ value:textBackgroundColor
[textStorage addAttribute:NSBackgroundColorAttributeName range:r];
value:previousBGColor
range:r];
}
else
{
[textStorage removeAttribute:NSBackgroundColorAttributeName
range:r];
}
highlighted_chars[i] = NSNotFound; highlighted_chars[i] = NSNotFound;
} }
@ -1424,10 +1415,6 @@ NSUInteger FindDelimiterInString(NSString * string,
NSAssert(textStorage, @"textstorage can't be nil"); NSAssert(textStorage, @"textstorage can't be nil");
// store the previous character's attributes // store the previous character's attributes
ASSIGN(previousBGColor,
[textStorage attribute:NSBackgroundColorAttributeName
atIndex:r.location
effectiveRange:NULL]);
ASSIGN(previousFont, [textStorage attribute:NSFontAttributeName ASSIGN(previousFont, [textStorage attribute:NSFontAttributeName
atIndex:r.location atIndex:r.location
effectiveRange:NULL]); effectiveRange:NULL]);