| Line 84... |
Line 84... |
| 84 |
if (!SPNSStringGetUTF8String) SPNSStringGetUTF8String = (SPUTF8StringMethodPtr)[NSString instanceMethodForSelector:@selector(UTF8String)];
|
84 |
if (!SPNSStringGetUTF8String) SPNSStringGetUTF8String = (SPUTF8StringMethodPtr)[NSString instanceMethodForSelector:@selector(UTF8String)];
|
| 85 |
const char* to_return = SPNSStringGetUTF8String(self, @selector(UTF8String));
|
85 |
const char* to_return = SPNSStringGetUTF8String(self, @selector(UTF8String));
|
| 86 |
return to_return;
|
86 |
return to_return;
|
| 87 |
}
|
87 |
}
|
| 88 |
|
88 |
|
| 89 |
static inline int RPARSERCONTEXTFORPOSITION (RTextView* self, NSUInteger index)
|
- |
|
| 90 |
{
|
- |
|
| 91 |
typedef int (*RPARSERCONTEXTFORPOSITIONMethodPtr)(RTextView*, SEL, NSUInteger);
|
- |
|
| 92 |
static RPARSERCONTEXTFORPOSITIONMethodPtr _RPARSERCONTEXTFORPOSITION;
|
- |
|
| 93 |
if (!_RPARSERCONTEXTFORPOSITION) _RPARSERCONTEXTFORPOSITION = (RPARSERCONTEXTFORPOSITIONMethodPtr)[self methodForSelector:@selector(parserContextForPosition:)];
|
- |
|
| 94 |
int r = _RPARSERCONTEXTFORPOSITION(self, @selector(parserContextForPosition:), index);
|
- |
|
| 95 |
return r;
|
- |
|
| 96 |
}
|
- |
|
| 97 |
|
- |
|
| 98 |
|
- |
|
| 99 |
@implementation RDocumentWinCtrl
|
89 |
@implementation RDocumentWinCtrl
|
| 100 |
|
90 |
|
| 101 |
//- (id)init { // NOTE: init is *not* used! put any initialization in windowDidLoad
|
91 |
//- (id)init { // NOTE: init is *not* used! put any initialization in windowDidLoad
|
| 102 |
|
92 |
|
| 103 |
static RDocumentWinCtrl *staticCodedRWC = nil;
|
93 |
static RDocumentWinCtrl *staticCodedRWC = nil;
|
| Line 361... |
Line 351... |
| 361 |
argsHints = [Preferences flagForKey:prefShowArgsHints withDefault:YES];
|
351 |
argsHints = [Preferences flagForKey:prefShowArgsHints withDefault:YES];
|
| 362 |
|
352 |
|
| 363 |
[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:showBraceHighlightingKey options:NSKeyValueObservingOptionNew context:NULL];
|
353 |
[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:showBraceHighlightingKey options:NSKeyValueObservingOptionNew context:NULL];
|
| 364 |
[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:prefShowArgsHints options:NSKeyValueObservingOptionNew context:NULL];
|
354 |
[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:prefShowArgsHints options:NSKeyValueObservingOptionNew context:NULL];
|
| 365 |
|
355 |
|
| - |
|
356 |
// FIXME: we did we use this?
|
| 366 |
[[self window] setBackgroundColor:[NSColor clearColor]];
|
357 |
//[[self window] setBackgroundColor:[NSColor clearColor]];
|
| 367 |
[[self window] setOpaque:NO];
|
358 |
//[[self window] setOpaque:NO];
|
| 368 |
|
359 |
|
| 369 |
SLog(@" - load document contents into textView");
|
360 |
SLog(@" - load document contents into textView");
|
| 370 |
[(RDocument*)[self document] loadInitialContents];
|
361 |
[(RDocument*)[self document] loadInitialContents];
|
| 371 |
|
362 |
|
| 372 |
// If not line wrapping update textView explicitly in order to set scrollView correctly
|
363 |
// If not line wrapping update textView explicitly in order to set scrollView correctly
|
| Line 410... |
Line 401... |
| 410 |
[[textView enclosingScrollView] setHasVerticalRuler:YES];
|
401 |
[[textView enclosingScrollView] setHasVerticalRuler:YES];
|
| 411 |
[[textView enclosingScrollView] setRulersVisible:YES];
|
402 |
[[textView enclosingScrollView] setRulersVisible:YES];
|
| 412 |
[theRulerView release];
|
403 |
[theRulerView release];
|
| 413 |
|
404 |
|
| 414 |
[(NoodleLineNumberView*)[[textView enclosingScrollView] verticalRulerView] setLineWrappingMode:[Preferences flagForKey:enableLineWrappingKey withDefault: YES]];
|
405 |
[(NoodleLineNumberView*)[[textView enclosingScrollView] verticalRulerView] setLineWrappingMode:[Preferences flagForKey:enableLineWrappingKey withDefault: YES]];
|
| 415 |
|
- |
|
| - |
|
406 |
[[self window] makeFirstResponder:theRulerView];
|
| 416 |
}
|
407 |
}
|
| 417 |
|
408 |
|
| 418 |
[self functionReset];
|
409 |
[self functionReset];
|
| 419 |
|
410 |
|
| 420 |
// Needed for showing tooltips of folded items
|
411 |
// Needed for showing tooltips of folded items
|
| 421 |
[[self window] setAcceptsMouseMovedEvents:YES];
|
412 |
[[self window] setAcceptsMouseMovedEvents:YES];
|
| - |
|
413 |
|
| - |
|
414 |
// FIXME: this is a hack for layout issues in Big Sur
|
| - |
|
415 |
// by forcing re-size we force layout to be updated - is there a better way?
|
| - |
|
416 |
NSRect clRect = [[self window] contentLayoutRect];
|
| - |
|
417 |
clRect.size.width += 1;
|
| - |
|
418 |
[[self window] setContentSize:clRect.size];
|
| - |
|
419 |
clRect.size.width -= 1;
|
| - |
|
420 |
[[self window] setContentSize:clRect.size];
|
| - |
|
421 |
|
| - |
|
422 |
// Make the text view fist responder so the user can start typing
|
| - |
|
423 |
[[self window] makeFirstResponder:textView];
|
| 422 |
|
424 |
|
| 423 |
SLog(@" - windowDidLoad is done");
|
425 |
SLog(@" - windowDidLoad is done");
|
| 424 |
|
426 |
|
| 425 |
return;
|
427 |
return;
|
| 426 |
|
428 |
|
| Line 784... |
Line 786... |
| 784 |
int li = r.location-1;
|
786 |
int li = r.location-1;
|
| 785 |
|
787 |
|
| 786 |
unichar fc;
|
788 |
unichar fc;
|
| 787 |
while (li>0 && ((fc=CFStringGetCharacterAtIndex((CFStringRef)s, li)) ==' ' || fc=='\t' || fc=='\r' || fc=='\n')) li--;
|
789 |
while (li>0 && ((fc=CFStringGetCharacterAtIndex((CFStringRef)s, li)) ==' ' || fc=='\t' || fc=='\r' || fc=='\n')) li--;
|
| 788 |
|
790 |
|
| 789 |
if(RPARSERCONTEXTFORPOSITION(textView, (li+2)) == pcComment)
|
791 |
if([textView parserContextForPosition: li + 2] == pcComment)
|
| 790 |
continue; // section declaration is commented out
|
792 |
continue; // section declaration is commented out
|
| 791 |
|
793 |
|
| 792 |
// due to finial bracket decrease range length by 1
|
794 |
// due to finial bracket decrease range length by 1
|
| 793 |
r.length--;
|
795 |
r.length--;
|
| 794 |
fn = [s substringWithRange:r];
|
796 |
fn = [s substringWithRange:r];
|
| Line 999... |
Line 1001... |
| 999 |
NSInteger cursorLocation = selRange.location;
|
1001 |
NSInteger cursorLocation = selRange.location;
|
| 1000 |
cursorLocation += shift; // add any shift as cursor movement guys need it
|
1002 |
cursorLocation += shift; // add any shift as cursor movement guys need it
|
| 1001 |
if (cursorLocation < 0 || cursorLocation >= completeStringLength) return;
|
1003 |
if (cursorLocation < 0 || cursorLocation >= completeStringLength) return;
|
| 1002 |
|
1004 |
|
| 1003 |
// bail if current character is in quotes or comments
|
1005 |
// bail if current character is in quotes or comments
|
| 1004 |
if(RPARSERCONTEXTFORPOSITION(textView, cursorLocation) != pcExpression) return;
|
1006 |
if([textView parserContextForPosition:cursorLocation] != pcExpression) return;
|
| 1005 |
|
1007 |
|
| 1006 |
unichar characterToCheck;
|
1008 |
unichar characterToCheck;
|
| 1007 |
unichar openingChar = 0;
|
1009 |
unichar openingChar = 0;
|
| 1008 |
characterToCheck = CFStringGetCharacterAtIndex((CFStringRef)completeString, cursorLocation);
|
1010 |
characterToCheck = CFStringGetCharacterAtIndex((CFStringRef)completeString, cursorLocation);
|
| 1009 |
int skipMatchingBrace = 0;
|
1011 |
int skipMatchingBrace = 0;
|
| Line 1017... |
Line 1019... |
| 1017 |
NSInteger breakCounter = 3000;
|
1019 |
NSInteger breakCounter = 3000;
|
| 1018 |
// well, this is rather simple so far, because it ignores cross-quoting, but for a first shot it's not too bad ;)
|
1020 |
// well, this is rather simple so far, because it ignores cross-quoting, but for a first shot it's not too bad ;)
|
| 1019 |
if (openingChar) {
|
1021 |
if (openingChar) {
|
| 1020 |
while (cursorLocation--) {
|
1022 |
while (cursorLocation--) {
|
| 1021 |
if(!breakCounter--) return;
|
1023 |
if(!breakCounter--) return;
|
| 1022 |
if(RPARSERCONTEXTFORPOSITION(textView, cursorLocation) == pcExpression) {
|
1024 |
if([textView parserContextForPosition:cursorLocation] == pcExpression) {
|
| 1023 |
c = CFStringGetCharacterAtIndex((CFStringRef)completeString, cursorLocation);
|
1025 |
c = CFStringGetCharacterAtIndex((CFStringRef)completeString, cursorLocation);
|
| 1024 |
if (c == openingChar) {
|
1026 |
if (c == openingChar) {
|
| 1025 |
if (!skipMatchingBrace) {
|
1027 |
if (!skipMatchingBrace) {
|
| 1026 |
[textView performSelector:@selector(highlightCharacter:) withObject:[NSNumber numberWithInt:cursorLocation] afterDelay:0.01];
|
1028 |
[textView performSelector:@selector(highlightCharacter:) withObject:[NSNumber numberWithInt:cursorLocation] afterDelay:0.01];
|
| 1027 |
return;
|
1029 |
return;
|
| Line 1039... |
Line 1041... |
| 1039 |
else if (characterToCheck == '[') openingChar=']';
|
1041 |
else if (characterToCheck == '[') openingChar=']';
|
| 1040 |
else if (characterToCheck == '{') openingChar='}';
|
1042 |
else if (characterToCheck == '{') openingChar='}';
|
| 1041 |
if (openingChar) {
|
1043 |
if (openingChar) {
|
| 1042 |
while ((++cursorLocation)<maxLimit) {
|
1044 |
while ((++cursorLocation)<maxLimit) {
|
| 1043 |
if(!breakCounter--) return;
|
1045 |
if(!breakCounter--) return;
|
| 1044 |
if(RPARSERCONTEXTFORPOSITION(textView, cursorLocation) == pcExpression) {
|
1046 |
if([textView parserContextForPosition:cursorLocation] == pcExpression) {
|
| 1045 |
c = CFStringGetCharacterAtIndex((CFStringRef)completeString, cursorLocation);
|
1047 |
c = CFStringGetCharacterAtIndex((CFStringRef)completeString, cursorLocation);
|
| 1046 |
if (c == openingChar) {
|
1048 |
if (c == openingChar) {
|
| 1047 |
if (!skipMatchingBrace) {
|
1049 |
if (!skipMatchingBrace) {
|
| 1048 |
[textView performSelector:@selector(highlightCharacter:) withObject:[NSNumber numberWithInt:cursorLocation] afterDelay:0.01];
|
1050 |
[textView performSelector:@selector(highlightCharacter:) withObject:[NSNumber numberWithInt:cursorLocation] afterDelay:0.01];
|
| 1049 |
return;
|
1051 |
return;
|
| Line 1135... |
Line 1137... |
| 1135 |
NSInteger lastClosedP = -1;
|
1137 |
NSInteger lastClosedP = -1;
|
| 1136 |
BOOL oneBlock = YES;
|
1138 |
BOOL oneBlock = YES;
|
| 1137 |
BOOL firstRun = YES;
|
1139 |
BOOL firstRun = YES;
|
| 1138 |
unichar c;
|
1140 |
unichar c;
|
| 1139 |
for(i=0; i<[line length]; i++) {
|
1141 |
for(i=0; i<[line length]; i++) {
|
| 1140 |
if(RPARSERCONTEXTFORPOSITION(textView, i) == pcExpression) {
|
1142 |
if([textView parserContextForPosition: i] == pcExpression) {
|
| 1141 |
c=CFStringGetCharacterAtIndex((CFStringRef)line,i);
|
1143 |
c=CFStringGetCharacterAtIndex((CFStringRef)line,i);
|
| 1142 |
if(c==')') {
|
1144 |
if(c==')') {
|
| 1143 |
cntP--;
|
1145 |
cntP--;
|
| 1144 |
lastClosedP = i;
|
1146 |
lastClosedP = i;
|
| 1145 |
}
|
1147 |
}
|
| Line 1620... |
Line 1622... |
| 1620 |
while(1) {
|
1622 |
while(1) {
|
| 1621 |
fr = [rtvstr rangeOfString:@"#" options:0 range:searchRange];
|
1623 |
fr = [rtvstr rangeOfString:@"#" options:0 range:searchRange];
|
| 1622 |
if(!fr.length) break;
|
1624 |
if(!fr.length) break;
|
| 1623 |
r = [rtvstr rangeOfRegex:comre options:0 inRange:NSMakeRange(fr.location, [rtvstr length]-fr.location) capture:1L error:nil];
|
1625 |
r = [rtvstr rangeOfRegex:comre options:0 inRange:NSMakeRange(fr.location, [rtvstr length]-fr.location) capture:1L error:nil];
|
| 1624 |
// check if first # is a comment character i.e. not quoted
|
1626 |
// check if first # is a comment character i.e. not quoted
|
| 1625 |
if(r.location+1 < [rtvstr length] && RPARSERCONTEXTFORPOSITION(rtv, r.location+1) == pcComment) {
|
1627 |
if(r.location+1 < [rtvstr length] && [rtv parserContextForPosition: r.location + 1] == pcComment) {
|
| 1626 |
rs = [rtvstr substringWithRange:[rtvstr rangeOfRegex:comre options:0 inRange:NSMakeRange(fr.location, [rtvstr length]-fr.location) capture:2L error:nil]];
|
1628 |
rs = [rtvstr substringWithRange:[rtvstr rangeOfRegex:comre options:0 inRange:NSMakeRange(fr.location, [rtvstr length]-fr.location) capture:2L error:nil]];
|
| 1627 |
rs = [rs stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
|
1629 |
rs = [rs stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
|
| 1628 |
rstr = [NSString stringWithFormat:@";c=\"@__@_@_@%@\"", rs];
|
1630 |
rstr = [NSString stringWithFormat:@";c=\"@__@_@_@%@\"", rs];
|
| 1629 |
[rtv replaceCharactersInRange:r withString:rstr];
|
1631 |
[rtv replaceCharactersInRange:r withString:rstr];
|
| 1630 |
[rtvstr flushCachedRegexData];
|
1632 |
[rtvstr flushCachedRegexData];
|