mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Change timing to color control characters
This commit is contained in:
parent
7b8f1de27d
commit
c42418b545
14
CHANGELOG.md
14
CHANGELOG.md
@ -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)
|
||||
--------------------------
|
||||
|
||||
|
@ -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
|
||||
|
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user