Skip to content

Commit 5faa322

Browse files
committed
Improved syntax coloring, fixed theme support.
1 parent 973cb10 commit 5faa322

File tree

4 files changed

+151
-31
lines changed

4 files changed

+151
-31
lines changed

SCXcodeMinimap.xcodeproj/project.pbxproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
/* Begin PBXFileReference section */
2323
1812C3911A77A7CF00E2CFB3 /* IDESourceCodeDocument.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = IDESourceCodeDocument.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
24+
18269AD51A8F2F4300953B3D /* DVTFoldingManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DVTFoldingManager.h; sourceTree = "<group>"; };
2425
184C11711A740F8A002A7C65 /* DVTCompletingTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = DVTCompletingTextView.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
2526
184C11721A740F8A002A7C65 /* DVTFontAndColorTheme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DVTFontAndColorTheme.h; sourceTree = "<group>"; };
2627
184C11731A740F8A002A7C65 /* DVTInvalidation-Protocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DVTInvalidation-Protocol.h"; sourceTree = "<group>"; };
@@ -85,11 +86,13 @@
8586
children = (
8687
184C11711A740F8A002A7C65 /* DVTCompletingTextView.h */,
8788
18C8F0331A7ECB1300C7A76F /* DVTFoldingLayoutManager.h */,
89+
18269AD51A8F2F4300953B3D /* DVTFoldingManager.h */,
8890
184C11721A740F8A002A7C65 /* DVTFontAndColorTheme.h */,
8991
184C11731A740F8A002A7C65 /* DVTInvalidation-Protocol.h */,
9092
18C8F0341A7ECB1300C7A76F /* DVTLayoutManager.h */,
9193
184C11741A740F8A002A7C65 /* DVTPointerArray.h */,
9294
184C11751A740F8A002A7C65 /* DVTPreferenceSet-Protocol.h */,
95+
18B3CEE51A8AA52A00A0873D /* DVTPreferenceSetManager.h */,
9396
184C11761A740F8A002A7C65 /* DVTSourceLanguageSourceModelService.h */,
9497
184C11771A740F8A002A7C65 /* DVTSourceModel.h */,
9598
184C11781A740F8A002A7C65 /* DVTSourceModelItem.h */,
@@ -104,7 +107,6 @@
104107
184C117E1A740F8A002A7C65 /* IDESourceCodeEditor.h */,
105108
184C117F1A740F8A002A7C65 /* IDESourceCodeEditorContainerView.h */,
106109
184C11801A740F8A002A7C65 /* IDEViewController.h */,
107-
18B3CEE51A8AA52A00A0873D /* DVTPreferenceSetManager.h */,
108110
);
109111
path = "Xcode Headers";
110112
sourceTree = "<group>";
@@ -148,10 +150,10 @@
148150
children = (
149151
18FE09C7170764E400118FEB /* SCXcodeMinimap.h */,
150152
18FE09C8170764E400118FEB /* SCXcodeMinimap.m */,
151-
184C11811A740F97002A7C65 /* SCXcodeMinimapSelectionView.h */,
152-
184C11821A740F97002A7C65 /* SCXcodeMinimapSelectionView.m */,
153153
184C11831A740F97002A7C65 /* SCXcodeMinimapView.h */,
154154
184C11841A740F97002A7C65 /* SCXcodeMinimapView.m */,
155+
184C11811A740F97002A7C65 /* SCXcodeMinimapSelectionView.h */,
156+
184C11821A740F97002A7C65 /* SCXcodeMinimapSelectionView.m */,
155157
18FE09BC1707639E00118FEB /* Supporting Files */,
156158
184C11701A740F8A002A7C65 /* Xcode Headers */,
157159
);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0500"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "18FE09B11707639E00118FEB"
18+
BuildableName = "SCXcodeMinimap.xcplugin"
19+
BlueprintName = "SCXcodeMinimap"
20+
ReferencedContainer = "container:SCXcodeMinimap.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
27+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28+
shouldUseLaunchSchemeArgsEnv = "YES"
29+
buildConfiguration = "Debug">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
selectedDebuggerIdentifier = ""
35+
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
36+
launchStyle = "0"
37+
useCustomWorkingDirectory = "NO"
38+
buildConfiguration = "Debug"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
allowLocationSimulation = "YES"
42+
viewDebuggingEnabled = "No">
43+
<PathRunnable
44+
FilePath = "/Applications/Xcode.app">
45+
</PathRunnable>
46+
<MacroExpansion>
47+
<BuildableReference
48+
BuildableIdentifier = "primary"
49+
BlueprintIdentifier = "18FE09B11707639E00118FEB"
50+
BuildableName = "SCXcodeMinimap.xcplugin"
51+
BlueprintName = "SCXcodeMinimap"
52+
ReferencedContainer = "container:SCXcodeMinimap.xcodeproj">
53+
</BuildableReference>
54+
</MacroExpansion>
55+
<AdditionalOptions>
56+
</AdditionalOptions>
57+
</LaunchAction>
58+
<ProfileAction
59+
shouldUseLaunchSchemeArgsEnv = "YES"
60+
savedToolIdentifier = ""
61+
useCustomWorkingDirectory = "NO"
62+
buildConfiguration = "Release"
63+
debugDocumentVersioning = "YES">
64+
</ProfileAction>
65+
<AnalyzeAction
66+
buildConfiguration = "Debug">
67+
</AnalyzeAction>
68+
<ArchiveAction
69+
buildConfiguration = "Release"
70+
revealArchiveInOrganizer = "YES">
71+
</ArchiveAction>
72+
</Scheme>

SCXcodeMinimap/SCXcodeMinimapView.m

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ - (void)setVisible:(BOOL)visible
142142

143143
if(visible) {
144144
[self updateOffset];
145-
146145
[self.textView.layoutManager setDelegate:self];
147-
} else {
148-
[self.textView.layoutManager setDelegate:nil];
149146
}
150147
}
151148

@@ -161,42 +158,43 @@ - (NSDictionary *)layoutManager:(NSLayoutManager *)layoutManager
161158
return nil;
162159
}
163160

164-
// Delay invalidation for performance reasons.
161+
// Delay invalidation for performance reasons and attempt a full range invalidation later
165162
if(!self.shouldAllowFullSyntaxHighlight) {
163+
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(invalidateVisibleMinimapRange) object:nil];
164+
[self performSelector:@selector(invalidateVisibleMinimapRange) withObject:nil afterDelay:kDurationBetweenInvalidations];
166165

167-
// Attempt a full range invalidation after
168-
__weak typeof(self) weakSelf = self;
169-
void(^invalidationBlock)() = ^{
170-
weakSelf.shouldAllowFullSyntaxHighlight = YES;
171-
NSRange visibleMinimapRange = [weakSelf.textView visibleCharacterRange];
172-
[weakSelf.textView.layoutManager invalidateDisplayForCharacterRange:visibleMinimapRange];
173-
};
174-
175-
[self performBlock:invalidationBlock afterDelay:kDurationBetweenInvalidations cancelPreviousRequest:YES];
176-
177-
return @{NSForegroundColorAttributeName : [self.theme sourcePlainTextColor]};
166+
return @{NSForegroundColorAttributeName : self.theme.sourcePlainTextColor};
178167
}
168+
169+
// Set background colors for comments and preprocessor directives
170+
short nodeType = [(DVTTextStorage *)[self.textView textStorage] nodeTypeAtCharacterIndex:charIndex
171+
effectiveRange:effectiveCharRange
172+
context:self.editorTextView.syntaxColoringContext];
179173

180-
// Rely on the colorAtCharacterIndex: method to update the effective range
181-
NSColor *color = [(DVTTextStorage *)[self.editorTextView textStorage] colorAtCharacterIndex:charIndex effectiveRange:effectiveCharRange context:nil];
182-
183-
// Background color for comments and preprocessor directives. Could query for nodeTypeAtCharacterIndex: but it's too slow.
184-
DVTPointerArray *editorColors = [[DVTFontAndColorTheme currentTheme] syntaxColorsByNodeType];
185-
if([color isEqual:[editorColors pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentNodeName]]] ||
186-
[color isEqual:[editorColors pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentDocNodeName]]] ||
187-
[color isEqual:[editorColors pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentDocKeywordNodeName]]])
174+
if(nodeType == [DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentNodeName] ||
175+
nodeType == [DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentDocNodeName] ||
176+
nodeType == [DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxCommentDocKeywordNodeName])
188177
{
189-
return @{NSForegroundColorAttributeName : [self.theme sourceTextBackgroundColor], NSBackgroundColorAttributeName : self.commentColor};
190-
} else if([color isEqual:[editorColors pointerAtIndex:[DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxPreprocessorNodeName]]]) {
191-
return @{NSForegroundColorAttributeName : [self.theme sourceTextBackgroundColor], NSBackgroundColorAttributeName : self.preprocessorColor};
178+
return @{NSForegroundColorAttributeName : self.theme.sourceTextBackgroundColor, NSBackgroundColorAttributeName : self.commentColor};
179+
} else if(nodeType == [DVTSourceNodeTypes registerNodeTypeNamed:kXcodeSyntaxPreprocessorNodeName]) {
180+
return @{NSForegroundColorAttributeName : self.theme.sourceTextBackgroundColor, NSBackgroundColorAttributeName : self.preprocessorColor};
192181
}
193182

194-
DVTPointerArray *minimapColors = [self.theme syntaxColorsByNodeType];
195-
color = [minimapColors pointerAtIndex:[editorColors indexOfPointerIdenticalTo:color]];
183+
NSColor *color = [self.theme.syntaxColorsByNodeType pointerAtIndex:nodeType];
184+
if(color == nil) {
185+
color = self.theme.sourcePlainTextColor;
186+
}
196187

197188
return @{NSForegroundColorAttributeName : color};
198189
}
199190

191+
- (void)invalidateVisibleMinimapRange
192+
{
193+
self.shouldAllowFullSyntaxHighlight = YES;
194+
NSRange visibleMinimapRange = [self.textView visibleCharacterRange];
195+
[self.textView.layoutManager invalidateDisplayForCharacterRange:visibleMinimapRange];
196+
}
197+
200198
- (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer atEnd:(BOOL)layoutFinishedFlag
201199
{
202200
self.shouldAllowFullSyntaxHighlight = NO;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Generated by class-dump 3.3.4 (64 bit).
3+
*
4+
* class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2011 by Steve Nygard.
5+
*/
6+
7+
@class DVTTextFold;
8+
@protocol DVTFoldingManagerDelegate;
9+
10+
@interface DVTFoldingManager : NSObject
11+
{
12+
DVTTextFold *_topLevelFold;
13+
id <DVTFoldingManagerDelegate> delegate;
14+
}
15+
16+
@property(retain, nonatomic) DVTTextFold *topLevelFold; // @synthesize topLevelFold=_topLevelFold;
17+
@property __weak id <DVTFoldingManagerDelegate> delegate; // @synthesize delegate;
18+
- (id)adjustFoldsForRange:(struct _NSRange)arg1 changeInLength:(long long)arg2;
19+
- (id)foldsEnclosingRange:(struct _NSRange)arg1;
20+
- (id)lastFoldTouchingCharacterIndex:(unsigned long long)arg1;
21+
- (id)firstFoldTouchingCharacterIndex:(unsigned long long)arg1;
22+
- (id)blockFoldsTouchingRange:(struct _NSRange)arg1;
23+
- (id)allFoldsTouchingRange:(struct _NSRange)arg1;
24+
- (BOOL)isRangeInsideAFold:(struct _NSRange)arg1;
25+
- (BOOL)isCharacterRangeFolded:(struct _NSRange)arg1;
26+
- (BOOL)containsFoldWithRange:(struct _NSRange)arg1;
27+
- (BOOL)isCharacterFoldedAtIndex:(unsigned long long)arg1;
28+
- (void)foldRecursiveItem:(id)arg1;
29+
- (void)unfoldItems:(id)arg1;
30+
- (void)foldItems:(id)arg1;
31+
- (void)unfoldRecursiveRange:(struct _NSRange)arg1;
32+
- (void)unfoldEnclosingRange:(struct _NSRange)arg1;
33+
- (void)unfoldRange:(struct _NSRange)arg1;
34+
- (void)unfoldAtCharacterIndex:(unsigned long long)arg1;
35+
- (void)unfoldAll;
36+
- (void)unfoldPlaceholdersInRange:(struct _NSRange)arg1;
37+
- (void)foldPlaceholderInRange:(struct _NSRange)arg1 withLabel:(id)arg2;
38+
- (void)foldRange:(struct _NSRange)arg1;
39+
- (void)_applyFoldsRecursively:(id)arg1;
40+
- (id)initWithRange:(struct _NSRange)arg1;
41+
- (id)init;
42+
43+
@end
44+
45+
@protocol DVTFoldingManagerDelegate <NSObject>
46+
- (void)foldingManager:(id)arg1 didUnfoldRange:(struct _NSRange)arg2;
47+
- (void)foldingManager:(id)arg1 didFoldRange:(struct _NSRange)arg2;
48+
@end

0 commit comments

Comments
 (0)