Change timing to color control characters

This commit is contained in:
1024jp 2015-10-26 22:41:45 +09:00
parent 7b8f1de27d
commit c42418b545
3 changed files with 40 additions and 36 deletions

View File

@ -2,6 +2,20 @@
Change Log
==========================
develop
--------------------------
### Additions/Changes
- Tweak UI text.
### Fixes
- Fix an issue where syntax highlighted control character was sometime not colored in the invisible color.
2.3.0-beta (80)
--------------------------

View File

@ -278,6 +278,30 @@ static BOOL usesTextFontForInvisibles;
}
// ------------------------------------------------------
/// color glyphs
- (void)showCGGlyphs:(const CGGlyph *)glyphs positions:(const NSPoint *)positions count:(NSUInteger)glyphCount font:(NSFont *)font matrix:(NSAffineTransform *)textMatrix attributes:(NSDictionary<NSString *,id> *)attributes inContext:(NSGraphicsContext *)graphicsContext
// ------------------------------------------------------
{
// overcort control glyphs
// -> Control color will occasionally be colored in sytnax style color after `drawGlyphsForGlyphRange:atPoint:`.
// So, it shoud be re-colored here.
BOOL isControlGlyph = (attributes[NSGlyphInfoAttributeName]);
if (isControlGlyph && [self showsControlCharacters]) {
NSColor *invisibleColor = [[(NSTextView<CETextViewProtocol> *)[self firstTextView] theme] invisiblesColor];
[graphicsContext saveGraphicsState];
[invisibleColor set];
}
[super showCGGlyphs:glyphs positions:positions count:glyphCount font:font matrix:textMatrix attributes:attributes inContext:graphicsContext];
// restore context
if (isControlGlyph) {
[graphicsContext restoreGraphicsState];
}
}
// ------------------------------------------------------
/// textStorage did update
- (void)textStorage:(NSTextStorage *)str edited:(NSTextStorageEditedOptions)editedMask range:(NSRange)newCharRange changeInLength:(NSInteger)delta invalidatedRange:(NSRange)invalidatedCharRange

View File

@ -35,8 +35,6 @@
// local constants (QC might abbr of Quotes/Comment)
static NSString *_Nonnull const InvisiblesType = @"invisibles";
static NSString *_Nonnull const QCLocationKey = @"QCLocationKey";
static NSString *_Nonnull const QCPairKindKey = @"QCPairKindKey";
static NSString *_Nonnull const QCStartEndKey = @"QCStartEndKey";
@ -692,27 +690,6 @@ static CGFloat kPerCompoIncrement;
}
// ------------------------------------------------------
///
- (nonnull NSArray<NSValue *> *)rangesOfControlCharsInString:(nonnull NSString *)string range:(NSRange)parseRange
// ------------------------------------------------------
{
NSMutableArray<NSValue *> *ranges = [NSMutableArray array];
NSCharacterSet *controlCharacterSet = [NSCharacterSet controlCharacterSet];
NSRange parsingRange = parseRange;
NSRange range;
while ((range = [string rangeOfCharacterFromSet:controlCharacterSet options:0 range:parsingRange]).location != NSNotFound) {
[ranges addObject:[NSValue valueWithRange:range]];
parsingRange.location += range.length;
parsingRange.length -= range.length;
}
return ranges;
}
// ------------------------------------------------------
///
- (nonnull NSDictionary<NSString *, NSArray<NSValue *> *> *)extractCommentsWithQuotesFromString:(nonnull NSString *)string range:(NSRange)parseRange
@ -964,9 +941,6 @@ static CGFloat kPerCompoIncrement;
if ([indicator isCancelled]) { return @{}; }
//
colorings[InvisiblesType] = [self rangesOfControlCharsInString:string range:parseRange];
return [colorings copy];
}
@ -1085,24 +1059,16 @@ static CGFloat kPerCompoIncrement;
[layoutManager removeTemporaryAttribute:NSForegroundColorAttributeName
forCharacterRange:coloringRange];
// add invisible coloring if needed
NSArray<NSString *> *colorTypes = kSyntaxDictKeys;
if ([layoutManager showsControlCharacters]) {
colorTypes = [colorTypes arrayByAddingObject:InvisiblesType];
}
//
CETheme *theme = [(NSTextView<CETextViewProtocol> *)[layoutManager firstTextView] theme];
for (NSString *colorType in colorTypes) {
for (NSString *colorType in kSyntaxDictKeys) {
NSArray<NSValue *> *ranges = colorings[colorType];
if ([ranges count] == 0) { continue; }
// get color from theme
NSColor *color;
if ([colorType isEqualToString:InvisiblesType]) {
color = [theme invisiblesColor];
} else if ([colorType isEqualToString:CESyntaxKeywordsKey]) {
if ([colorType isEqualToString:CESyntaxKeywordsKey]) {
color = [theme keywordsColor];
} else if ([colorType isEqualToString:CESyntaxCommandsKey]) {
color = [theme commandsColor];