Skip to content

Commit

Permalink
Fixed delegate colouring exmaple code in FragariaAppDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Mitchell committed Apr 16, 2013
1 parent ec8f2ea commit 26b489c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
28 changes: 16 additions & 12 deletions FragariaAppDelegate.m
Expand Up @@ -252,7 +252,7 @@ - (void) fragariaDocument:(id)document willColourWithBlock:(BOOL (^)(NSDictionar
#pragma unused(document, colourWithBlock, string, range, info)
NSLog(@"Will colour document.");

// we can call colourWithBlock to perform initial colouration
// we can call colourWithBlock to perform initial colouring
}
/*
Expand All @@ -276,7 +276,6 @@ - (BOOL) fragariaDocument:(id)document willColourGroupWithBlock:(BOOL (^)(NSDict
// compiler comfort
(void)syntaxInfo;


NSLog(@"willColourGroupWithBlock Colouring group : %@ id : %li caller will colour : %@", group, groupID, (willColour ? @"YES" : @"NO"));

// group
Expand Down Expand Up @@ -367,7 +366,6 @@ - (void) fragariaDocument:(id)document didColourGroupWithBlock:(BOOL (^)(NSDicti
// group
switch (groupID) {
case kSMLSyntaxGroupNumber:

break;

case kSMLSyntaxGroupCommand:
Expand All @@ -378,14 +376,21 @@ - (void) fragariaDocument:(id)document didColourGroupWithBlock:(BOOL (^)(NSDicti

case kSMLSyntaxGroupKeyword:
{
// normally we iterate over the string using an NSScanner to identiy our substrings.
// we can iterate over the string using an NSScanner to identiy our substrings or use a regex.
// in this simple case we just colour the occurence of a given string as a false keyword.
NSString *fauxKeyword = @" noodle";
while (![rangeScanner isAtEnd]) {
if ([rangeScanner scanUpToString:fauxKeyword intoString:nil]) {
NSUInteger location = [rangeScanner scanLocation];
NSRange testRange = NSMakeRange(location, [fauxKeyword length]);
colourWithBlock(attributes, testRange);
NSString *fauxKeyword = @"kosmic";
while (YES) {

// look for the keyword
[rangeScanner scanUpToString:fauxKeyword intoString:nil];
if ([rangeScanner isAtEnd]) break;

NSUInteger location = [rangeScanner scanLocation];
if ([rangeScanner scanString:fauxKeyword intoString:NULL]) {
NSRange colourRange = NSMakeRange(range.location + location, [rangeScanner scanLocation] - location);

// the block will colour the string
colourWithBlock(attributes, colourRange);
}
}
}
Expand Down Expand Up @@ -417,7 +422,6 @@ - (void) fragariaDocument:(id)document didColourGroupWithBlock:(BOOL (^)(NSDicti
}
}


/*
- fragariaDocument:willColourWithBlock:string:range:info
Expand All @@ -428,7 +432,7 @@ - (void) fragariaDocument:(id)document didColourWithBlock:(BOOL (^)(NSDictionary
#pragma unused(document, colourWithBlock, string, range, info)
NSLog(@"Did colour document.");

// we can call colourWithBlock to perform final colouration
// we can call colourWithBlock to perform final colouring

}
@end
6 changes: 4 additions & 2 deletions MGSFragaria.m
Expand Up @@ -328,10 +328,12 @@ - (void)embedInView:(NSView *)contentView

// create line numbers
SMLLineNumbers *lineNumbers = [[[lineNumberClass alloc] initWithDocument:self.docSpec] autorelease];
[[NSNotificationCenter defaultCenter] addObserver:lineNumbers selector:@selector(viewBoundsDidChange:) name:NSViewBoundsDidChangeNotification object:[textScrollView contentView]];
[[NSNotificationCenter defaultCenter] addObserver:lineNumbers selector:@selector(viewBoundsDidChange:) name:NSViewFrameDidChangeNotification object:[textScrollView contentView]];
[self.docSpec setValue:lineNumbers forKey:ro_MGSFOLineNumbers];

// SMLLineNumbers will be notified of changes to the text scroll view content view due to scrolling
[[NSNotificationCenter defaultCenter] addObserver:lineNumbers selector:@selector(viewBoundsDidChange:) name:NSViewBoundsDidChangeNotification object:[textScrollView contentView]];
[[NSNotificationCenter defaultCenter] addObserver:lineNumbers selector:@selector(viewBoundsDidChange:) name:NSViewFrameDidChangeNotification object:[textScrollView contentView]];

// create gutter scrollview
NSScrollView *gutterScrollView = [[[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, gutterWidth, contentSize.height)] autorelease];
[gutterScrollView setBorderType:NSNoBorder];
Expand Down
4 changes: 4 additions & 0 deletions SMLSyntaxColouring.m
Expand Up @@ -818,6 +818,8 @@ - (void)recolourRange:(NSRange)rangeToRecolour
NSUInteger queryLocation = 0;
unichar testCharacter = 0;

//NSLog(@"rangeToRecolor location %i length %i", rangeToRecolour.location, rangeToRecolour.length);

// adjust effective range
//
// When multiline strings are coloured we need to scan backwards to
Expand All @@ -831,6 +833,8 @@ - (void)recolourRange:(NSRange)rangeToRecolour
}
}

NSLog(@"rangeToRecolor location %i length %i", effectiveRange.location, effectiveRange.length);

// setup working locations based on teh effective range
NSUInteger rangeLocation = effectiveRange.location;
NSUInteger maxRangeLocation = NSMaxRange(effectiveRange);
Expand Down

0 comments on commit 26b489c

Please sign in to comment.