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 *backgroundColor;
NSColor *readOnlyColor;
NSColor *textBackground;
NSColor *textBackgroundColor;
// location of the highlighted delimiter characters
// NSNotFound means not set
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
NSColor *previousBGColor;
// A pair is assumed to have the same attributes
NSColor *previousFont;
// This is used to protect that -textViewDidChangeSelection: invocations

View file

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