From a0856faf214924e432b74feeff86f2fec350c43f Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 23 Nov 2021 01:09:50 +0100 Subject: [PATCH] remane textBackground to textBackgroundColor and use that for restoring highlit characters, without resding/storing such attribute --- Modules/Editors/ProjectCenter/PCEditor.h | 6 ++--- Modules/Editors/ProjectCenter/PCEditor.m | 29 +++++++----------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/Modules/Editors/ProjectCenter/PCEditor.h b/Modules/Editors/ProjectCenter/PCEditor.h index f9b0531..637283d 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.h +++ b/Modules/Editors/ProjectCenter/PCEditor.h @@ -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 diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m index 1063721..55330e0 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.m +++ b/Modules/Editors/ProjectCenter/PCEditor.m @@ -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]);