The R Project SVN R-packages

Rev

Rev 6233 | Rev 6242 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6233 Rev 6238
Line 34... Line 34...
34
 
34
 
35
#import "RScriptEditorTextView.h"
35
#import "RScriptEditorTextView.h"
36
#import "RScriptEditorTextStorage.h"
36
#import "RScriptEditorTextStorage.h"
37
#import "RScriptEditorTypeSetter.h"
37
#import "RScriptEditorTypeSetter.h"
38
#import "RScriptEditorLayoutManager.h"
38
#import "RScriptEditorLayoutManager.h"
39
#import "FoldingSignTextAttachmentCell.h"
-
 
40
#import "RGUI.h"
39
#import "RGUI.h"
-
 
40
#import "Tools/RTooltip.h"
41
 
41
 
42
 
42
 
43
#pragma mark -
43
#pragma mark -
44
#pragma mark flex init
44
#pragma mark flex init
45
 
45
 
Line 144... Line 144...
144
 
144
 
145
	// Set self as delegate for the textView's textStorage to enable syntax highlighting,
145
	// Set self as delegate for the textView's textStorage to enable syntax highlighting,
146
	[theTextStorage setDelegate:self];
146
	[theTextStorage setDelegate:self];
147
	_foldedImp = [theTextStorage methodForSelector:_foldedSel];
147
	_foldedImp = [theTextStorage methodForSelector:_foldedSel];
148
 
148
 
149
	// <TODO> enable for folding
-
 
150
	// Make sure using foldingLayoutManager
149
	// Make sure using foldingLayoutManager
151
	// if (![[self layoutManager] isKindOfClass:[RScriptEditorLayoutManager class]]) {
150
	if (![[self layoutManager] isKindOfClass:[RScriptEditorLayoutManager class]]) {
152
	// 	RScriptEditorLayoutManager *layoutManager = [[RScriptEditorLayoutManager alloc] init];
151
		RScriptEditorLayoutManager *layoutManager = [[RScriptEditorLayoutManager alloc] init];
153
	// 	[[self textContainer] replaceLayoutManager:layoutManager];
152
		[[self textContainer] replaceLayoutManager:layoutManager];
154
	// 	[layoutManager release];
153
		[layoutManager release];
155
	// }
154
	}
156
 
155
 
157
	// disabled to get the current text range in textView safer
156
	// disabled to get the current text range in textView safer
158
	[[self layoutManager] setBackgroundLayoutEnabled:NO];
157
	[[self layoutManager] setBackgroundLayoutEnabled:NO];
159
	[[self layoutManager] replaceTextStorage:theTextStorage];
158
	[[self layoutManager] replaceTextStorage:theTextStorage];
160
 
159
 
161
	// <TODO> enable for folding
-
 
162
	// [(RScriptEditorTypeSetter*)[[self layoutManager] typesetter] setTextStorage:theTextStorage];
160
	[(RScriptEditorTypeSetter*)[[self layoutManager] typesetter] setTextStorage:theTextStorage];
163
 
161
 
164
	isSyntaxHighlighting = NO;
162
	isSyntaxHighlighting = NO;
165
 
163
 
166
	if([prefs objectForKey:highlightCurrentLine] == nil) [prefs setBool:YES forKey:highlightCurrentLine];
164
	if([prefs objectForKey:highlightCurrentLine] == nil) [prefs setBool:YES forKey:highlightCurrentLine];
167
	if([prefs objectForKey:indentNewLines] == nil) [prefs setBool:YES forKey:indentNewLines];
165
	if([prefs objectForKey:indentNewLines] == nil) [prefs setBool:YES forKey:indentNewLines];
Line 320... Line 318...
320
	}
318
	}
321
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
319
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
322
	[[self layoutManager] setAllowsNonContiguousLayout:YES];
320
	[[self layoutManager] setAllowsNonContiguousLayout:YES];
323
#endif
321
#endif
324
 
322
 
325
 
-
 
326
}
323
}
327
 
324
 
328
- (void)dealloc {
325
- (void)dealloc {
329
	SLog(@"RScriptEditorTextView: dealloc <%@>", self);
326
	SLog(@"RScriptEditorTextView: dealloc <%@>", self);
330
 
327
 
Line 458... Line 455...
458
		} else {
455
		} else {
459
			[self performSelector:@selector(setNonSyntaxHighlighting) withObject:nil afterDelay:0.05f];
456
			[self performSelector:@selector(setNonSyntaxHighlighting) withObject:nil afterDelay:0.05f];
460
		}
457
		}
461
	} else if ([keyPath isEqualToString:enableLineWrappingKey]) {
458
	} else if ([keyPath isEqualToString:enableLineWrappingKey]) {
462
		[self updateLineWrappingMode];
459
		[self updateLineWrappingMode];
-
 
460
		[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.05f];
463
		[self setNeedsDisplayInRect:[self bounds]];
461
		[self setNeedsDisplay:YES];
464
 
462
 
465
	} else if ([keyPath isEqualToString:showLineNumbersKey]) {
463
	} else if ([keyPath isEqualToString:showLineNumbersKey]) {
466
		lineNumberingEnabled = [[change objectForKey:NSKeyValueChangeNewKey] boolValue];
464
		lineNumberingEnabled = [[change objectForKey:NSKeyValueChangeNewKey] boolValue];
467
		if(lineNumberingEnabled) {
465
		if(lineNumberingEnabled) {
468
			NoodleLineNumberView *theRulerView = [[NoodleLineNumberView alloc] initWithScrollView:scrollView];
466
			NoodleLineNumberView *theRulerView = [[NoodleLineNumberView alloc] initWithScrollView:scrollView];
469
			[scrollView setVerticalRulerView:theRulerView];
467
			[scrollView setVerticalRulerView:theRulerView];
470
			[scrollView setHasHorizontalRuler:NO];
468
			[scrollView setHasHorizontalRuler:NO];
471
			[scrollView setHasVerticalRuler:YES];
469
			[scrollView setHasVerticalRuler:YES];
472
			[scrollView setRulersVisible:YES];
470
			[scrollView setRulersVisible:YES];
473
			[theRulerView release];
471
			[theRulerView release];
-
 
472
			[(NoodleLineNumberView*)[[self enclosingScrollView] verticalRulerView] setLineWrappingMode:[Preferences flagForKey:enableLineWrappingKey withDefault: YES]];
474
		} else {
473
		} else {
475
			[scrollView setHasHorizontalRuler:NO];
474
			[scrollView setHasHorizontalRuler:NO];
476
			[scrollView setHasVerticalRuler:NO];
475
			[scrollView setHasVerticalRuler:NO];
477
			[scrollView setRulersVisible:NO];
476
			[scrollView setRulersVisible:NO];
478
		}
477
		}
Line 499... Line 498...
499
}
498
}
500
 
499
 
501
- (void)updateLineWrappingMode
500
- (void)updateLineWrappingMode
502
{
501
{
503
 
502
 
504
	NSSize layoutSize;
-
 
505
 
-
 
506
	lineWrappingEnabled = [Preferences flagForKey:enableLineWrappingKey withDefault: YES];
503
	lineWrappingEnabled = [Preferences flagForKey:enableLineWrappingKey withDefault: YES];
-
 
504
 
-
 
505
	NSSize contentSize = [scrollView contentSize];
-
 
506
	NSTextContainer *textContainer = [self textContainer];
-
 
507
 
507
	[self setHorizontallyResizable:YES];
508
	// [self setMinSize:contentSize];
-
 
509
 
508
	if (!lineWrappingEnabled) {
510
	if (lineWrappingEnabled) {
509
		layoutSize = NSMakeSize(10e6,10e6);
-
 
510
		[scrollView setHasHorizontalScroller:YES];
511
		[scrollView setHasHorizontalScroller:YES];
511
		[self setMaxSize:layoutSize];
512
		[textContainer setContainerSize:NSMakeSize(contentSize.width, CGFLOAT_MAX)];
512
		[[self textContainer] setContainerSize:layoutSize];
513
		[textContainer setWidthTracksTextView:YES];
513
		[[self textContainer] setWidthTracksTextView:NO];
514
		[self setHorizontallyResizable:NO];
-
 
515
		[(NoodleLineNumberView*)[[self enclosingScrollView] verticalRulerView] setLineWrappingMode:YES];
514
	} else {
516
	} else {
515
		[scrollView setHasHorizontalScroller:NO];
517
		[scrollView setHasHorizontalScroller:YES];
516
		layoutSize = [self maxSize];
-
 
517
		[self setMaxSize:layoutSize];
-
 
518
		[[self textContainer] setContainerSize:layoutSize];
518
		[textContainer setContainerSize:NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX)];
519
		[[self textContainer] setWidthTracksTextView:YES];
519
		[textContainer setWidthTracksTextView:NO];
520
		// Enforce view to be re-layouted correctly
-
 
521
		[[self undoManager] disableUndoRegistration];
-
 
522
		[self selectAll:nil];
520
		[self setHorizontallyResizable:YES];
523
		[self cut:nil];
-
 
524
		[self paste:nil];
-
 
525
		[[self undoManager] enableUndoRegistration];
521
		[(NoodleLineNumberView*)[[self enclosingScrollView] verticalRulerView] setLineWrappingMode:NO];
526
	}
522
	}
527
	[[self textContainer] setHeightTracksTextView:NO];
-
 
528
 
523
 
529
	[[[self enclosingScrollView] verticalRulerView] performSelector:@selector(refresh) withObject:nil afterDelay:0.0f];
524
	[[[self enclosingScrollView] verticalRulerView] performSelector:@selector(refresh) withObject:nil afterDelay:0.0f];
530
 
525
 
-
 
526
	// NSSize layoutSize;
-
 
527
	// 
-
 
528
	// lineWrappingEnabled = [Preferences flagForKey:enableLineWrappingKey withDefault: YES];
-
 
529
	// [self setHorizontallyResizable:YES];
-
 
530
	// if (!lineWrappingEnabled) {
-
 
531
	// 	layoutSize = NSMakeSize(10e6,10e6);
-
 
532
	// 	[scrollView setHasHorizontalScroller:YES];
-
 
533
	// 	[self setMaxSize:layoutSize];
-
 
534
	// 	[[self textContainer] setContainerSize:layoutSize];
-
 
535
	// 	[[self textContainer] setWidthTracksTextView:NO];
-
 
536
	// } else {
-
 
537
	// 	[scrollView setHasHorizontalScroller:NO];
-
 
538
	// 	layoutSize = [self maxSize];
-
 
539
	// 	[self setMaxSize:layoutSize];
-
 
540
	// 	[[self textContainer] setContainerSize:layoutSize];
-
 
541
	// 	[[self textContainer] setWidthTracksTextView:YES];
-
 
542
	// 	// Enforce view to be re-layouted correctly
-
 
543
	// 	[[self undoManager] disableUndoRegistration];
-
 
544
	// 	[self selectAll:nil];
-
 
545
	// 	[self cut:nil];
-
 
546
	// 	[self paste:nil];
-
 
547
	// 	[[self undoManager] enableUndoRegistration];
-
 
548
	// }
-
 
549
	// [[self textContainer] setHeightTracksTextView:NO];
-
 
550
 
-
 
551
 
531
}
552
}
532
 
553
 
533
- (void)drawRect:(NSRect)rect
554
- (void)drawRect:(NSRect)rect
534
{
555
{
535
	// Draw background only for screen display but not while printing
556
	// Draw background only for screen display but not while printing
Line 537... Line 558...
537
 
558
 
538
		// Draw textview's background
559
		// Draw textview's background
539
		[shColorBackground setFill];
560
		[shColorBackground setFill];
540
		NSRectFill(rect);
561
		NSRectFill(rect);
541
 
562
 
542
		// Highlightes the current query if set in the Pref
563
		// Highlightes the current line if set in the Pref
543
		// and if nothing is selected in the text view
564
		// and if nothing is selected in the text view
544
		if ([prefs boolForKey:highlightCurrentLine] && ![self selectedRange].length && ![self isSnippetMode]) {
565
		if ([prefs boolForKey:highlightCurrentLine] && ![self selectedRange].length && ![self isSnippetMode]) {
545
			NSUInteger rectCount;
566
			NSUInteger rectCount;
546
			NSRange curLineRange = [[self string] lineRangeForRange:[self selectedRange]];
567
			NSRange curLineRange = [[self string] lineRangeForRange:[self selectedRange]];
547
			[theTextStorage ensureAttributesAreFixedInRange:curLineRange];
568
			[theTextStorage ensureAttributesAreFixedInRange:curLineRange];
Line 802... Line 823...
802
 
823
 
803
	} else {
824
	} else {
804
 
825
 
805
		yy_switch_to_buffer(yy_scan_string(NSStringUTF8String([selfstr substringWithRange:textRange])));
826
		yy_switch_to_buffer(yy_scan_string(NSStringUTF8String([selfstr substringWithRange:textRange])));
806
 
827
 
807
 
-
 
808
// NSDate *d1 = [NSDate date];
-
 
809
 
-
 
810
		// now loop through all the tokens
828
		// now loop through all the tokens
811
		while ((token = yylex())) {
829
		while ((token = yylex())) {
812
			if(hasFoldedItems && (NSInteger)(_foldedImp)(theTextStorage, _foldedSel, yyuoffset) > -1) continue;
830
			if(hasFoldedItems && (NSInteger)(_foldedImp)(theTextStorage, _foldedSel, yyuoffset) > -1) continue;
813
			switch (token) {
831
			switch (token) {
814
				case RPT_SINGLE_QUOTED_TEXT:
832
				case RPT_SINGLE_QUOTED_TEXT:
Line 836... Line 854...
836
 
854
 
837
			tokenRange = NSMakeRange(yyuoffset, yyuleng);
855
			tokenRange = NSMakeRange(yyuoffset, yyuleng);
838
 
856
 
839
			// make sure that tokenRange is valid (and therefore within textRange)
857
			// make sure that tokenRange is valid (and therefore within textRange)
840
			// otherwise a bug in the lex code could cause the the TextView to crash
858
			// otherwise a bug in the lex code could cause the the TextView to crash
841
			// NOTE Disabled for testing purposes for speed it up
-
 
842
			tokenRange = NSIntersectionRange(tokenRange, textRange);
859
			tokenRange = NSIntersectionRange(tokenRange, textRange);
843
			if (!tokenRange.length) continue;
860
			if (!tokenRange.length) continue;
844
 
861
 
845
			NSMutableAttributedStringAddAttributeValueRange(theTextStorage, NSForegroundColorAttributeName, tokenColor, tokenRange);
862
			NSMutableAttributedStringAddAttributeValueRange(theTextStorage, NSForegroundColorAttributeName, tokenColor, tokenRange);
846
 
863
 
Line 858... Line 875...
858
 
875
 
859
			}
876
			}
860
 
877
 
861
		}
878
		}
862
 
879
 
863
// NSLog(@"bibiko1 t %f", [[NSDate date] timeIntervalSinceDate:d1]);
-
 
864
 
-
 
865
	}
880
	}
866
 
881
 
867
	// set current textColor to the color of the caret's position - 1
882
	// set current textColor to the color of the caret's position - 1
868
	// to try to suppress writing in normalColor before syntax highlighting 
883
	// to try to suppress writing in normalColor before syntax highlighting 
869
	NSUInteger ix = [self selectedRange].location;
884
	NSUInteger ix = [self selectedRange].location;
Line 950... Line 965...
950
		if(![theTextStorage changeInLength]) {
965
		if(![theTextStorage changeInLength]) {
951
			if([[theTextStorage string] length] > 120000)
966
			if([[theTextStorage string] length] > 120000)
952
				breakSyntaxHighlighting = 2;
967
				breakSyntaxHighlighting = 2;
953
			[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.05];
968
			[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.05];
954
		}
969
		}
-
 
970
		if(lineNumberingEnabled) {
-
 
971
			[NSObject cancelPreviousPerformRequestsWithTarget:[[self enclosingScrollView] verticalRulerView] 
-
 
972
										selector:@selector(refresh) 
-
 
973
										object:nil];
-
 
974
			
-
 
975
			[[[self enclosingScrollView] verticalRulerView] performSelector:@selector(refresh) withObject:nil afterDelay:0.001f];
-
 
976
		}
955
 
977
 
956
	}
978
	}
957
 
979
 
958
}
980
}
959
 
981
 
Line 976... Line 998...
976
}
998
}
977
 
999
 
978
#pragma mark -
1000
#pragma mark -
979
#pragma mark Folding
1001
#pragma mark Folding
980
 
1002
 
-
 
1003
/*
-
 
1004
The idea of code folding is to replace the folded range while layouting by NSControlGlyphs
-
 
1005
which will be rendered as zero width glyphs. This has the advantage that all text actions like 
-
 
1006
copying, line numbering, etc. works without additional stuff.
-
 
1007
 
-
 
1008
For now it is only possible to fold a block if:
-
 
1009
- the starting { is placed at the end of a line (or with a following comment)
-
 
1010
- there's only ONE starting { in that line and NO }
-
 
1011
- the ending } is placed at the of a line (or with a following comment)
-
 
1012
- there's only ONE ending } in that line and NO {
-
 
1013
 
-
 
1014
Due to speed issues all folded ranges will be stored in a 3d C array of the size
-
 
1015
R_MAX_FOLDED_ITEMS = 1024 defined in RScriptEditorTextStorage.h whereby index:
-
 
1016
0 - range location
-
 
1017
1 - range length
-
 
1018
2 - location + length (pre-calculate for speed)
-
 
1019
 
-
 
1020
If the user locates the cursor inside a folded range or an action will locate the cursor
-
 
1021
inside such a range (go to line, find something) the folded range will be unfolded.
-
 
1022
... for more info ask Hans-J. Bibiko
-
 
1023
*/
-
 
1024
 
-
 
1025
- (IBAction)unfoldCurrentBlock:(id)sender
-
 
1026
{
-
 
1027
	NSUInteger caretPosition = [self selectedRange].location;
-
 
1028
 
-
 
1029
	NSRange r = [[self string] lineRangeForRange:NSMakeRange(caretPosition, 0)];
-
 
1030
 
-
 
1031
	if([theTextStorage foldedAtIndex:NSMaxRange(r)] > -1) {
-
 
1032
		[self unfoldLinesContainingCharacterAtIndex:NSMaxRange(r)];
-
 
1033
		return;
-
 
1034
	}
-
 
1035
	if([theTextStorage foldedAtIndex:r.location] > -1) {
-
 
1036
		[self unfoldLinesContainingCharacterAtIndex:r.location];
-
 
1037
		return;
-
 
1038
	}
-
 
1039
}
-
 
1040
 
981
- (void)foldLinesInRange:(NSRange)range
1041
- (IBAction)foldCurrentBlock:(id)sender
982
{
1042
{
-
 
1043
	NSUInteger caretPosition = [self selectedRange].location;
-
 
1044
	NSInteger foldItem = 0;
-
 
1045
	unichar c;
-
 
1046
 
-
 
1047
	NSRange r = [[self string] lineRangeForRange:NSMakeRange(caretPosition, 0)];
-
 
1048
 
-
 
1049
	foldItem = [self foldStatusAtIndex:NSMaxRange(r)-2];
-
 
1050
	if(foldItem == 1) { // is current line set to ▼ set caret to end of line
-
 
1051
		caretPosition = NSMaxRange(r)-1;
-
 
1052
	} else { // otherwise set caret to begin of line
-
 
1053
		caretPosition = r.location;
-
 
1054
	}
-
 
1055
	
-
 
1056
	NSUInteger stringLength = [[self string] length];
983
	if(range.length < 2) return;
1057
	if(!stringLength) return;
-
 
1058
	if(caretPosition == 0 || caretPosition >= [[self string] length]) return;
-
 
1059
		
-
 
1060
	CFStringRef parserStringRef = (CFStringRef)[self string];
-
 
1061
 
-
 
1062
	unichar co = '{'; // opening char
-
 
1063
	unichar cc = '}'; // closing char
-
 
1064
	
-
 
1065
	NSInteger start = -1;
-
 
1066
	NSInteger end = -1;
-
 
1067
	NSInteger bracketCounter = 0;
-
 
1068
 
-
 
1069
	c = CFStringGetCharacterAtIndex(parserStringRef, caretPosition);
-
 
1070
	if(c == cc)
-
 
1071
		bracketCounter--;
-
 
1072
	if(c == co)
-
 
1073
		bracketCounter++;
-
 
1074
 
-
 
1075
	for(NSInteger i=caretPosition; i>=0; i--) {
-
 
1076
		if([self parserContextForPosition:i] != pcExpression) continue;
-
 
1077
		c = CFStringGetCharacterAtIndex(parserStringRef, i);
-
 
1078
		if(c == co) {
-
 
1079
			if(!bracketCounter) {
-
 
1080
				start = i;
-
 
1081
				break;
-
 
1082
			}
-
 
1083
			bracketCounter--;
-
 
1084
		}
-
 
1085
		if(c == cc) {
-
 
1086
			bracketCounter++;
-
 
1087
		}
-
 
1088
	}
-
 
1089
	if(start < 0 ) return;
-
 
1090
 
-
 
1091
	// go up for lines like "} else {"
-
 
1092
	if(start && [self foldStatusAtIndex:start-1] == 0) {
-
 
1093
		for(NSInteger i=start-1; i>=0; i--) {
-
 
1094
			c = CFStringGetCharacterAtIndex(parserStringRef, i);
-
 
1095
			if(c == '\n' || c == '\r') break;
-
 
1096
			if([self parserContextForPosition:i] != pcExpression) continue;
-
 
1097
			if(c == cc && i > 0) {
-
 
1098
				bracketCounter = 0;
-
 
1099
				for(NSInteger j=i-1; j>=0; j--) {
-
 
1100
					if([self parserContextForPosition:j] != pcExpression) continue;
-
 
1101
					c = CFStringGetCharacterAtIndex(parserStringRef, j);
-
 
1102
					if(c == co) {
-
 
1103
						if(!bracketCounter) {
-
 
1104
							start = j;
-
 
1105
							break;
-
 
1106
						}
-
 
1107
						bracketCounter--;
-
 
1108
					}
-
 
1109
					if(c == cc) {
-
 
1110
						bracketCounter++;
-
 
1111
					}
-
 
1112
				}
-
 
1113
				break;
-
 
1114
			}
-
 
1115
		}
-
 
1116
	}		
-
 
1117
 
-
 
1118
 
-
 
1119
	bracketCounter = 0;
-
 
1120
	for(NSUInteger i=caretPosition; i<stringLength; i++) {
-
 
1121
		if([self parserContextForPosition:i] != pcExpression) continue;
-
 
1122
		c = CFStringGetCharacterAtIndex(parserStringRef, i);
-
 
1123
		if(c == co) {
-
 
1124
			bracketCounter++;
-
 
1125
		}
-
 
1126
		if(c == cc) {
-
 
1127
			if(!bracketCounter) {
-
 
1128
				end = i+1;
-
 
1129
				BOOL goAhead = NO;
-
 
1130
				//go ahead for lines a la  "} else {"
-
 
1131
				for(NSUInteger j=end; j<stringLength; j++) {
-
 
1132
					c = CFStringGetCharacterAtIndex(parserStringRef, j);
-
 
1133
					if(c == '\n' || c == '\r') {
-
 
1134
						break;
-
 
1135
					}
-
 
1136
					if(c == '\t' || c == ' ') {
-
 
1137
						continue;
-
 
1138
					}
-
 
1139
					if([self parserContextForPosition:j] != pcExpression) continue;
-
 
1140
					if(c == co) {
-
 
1141
						goAhead = YES;
-
 
1142
						break;
-
 
1143
					}
-
 
1144
				}
-
 
1145
				if(!goAhead) break;
-
 
1146
			}
-
 
1147
			bracketCounter--;
-
 
1148
		}
-
 
1149
	}
-
 
1150
 
-
 
1151
	if(end < 0 || bracketCounter || end-start < 1) return;
-
 
1152
 
-
 
1153
	NSRange foldRange = NSMakeRange(start, end-start);
-
 
1154
	if(![theTextStorage existsFoldedRange:foldRange]) {
-
 
1155
		// set caret for ▲ line inside {} for scrolling
-
 
1156
		if(foldItem == 2)
-
 
1157
			[self setSelectedRange:NSMakeRange(r.location, 0)];
-
 
1158
		[self foldLinesInRange:foldRange];
-
 
1159
	}
984
 
1160
 
-
 
1161
}
-
 
1162
 
-
 
1163
- (IBAction)foldBlockAtLevel:(id)sender
-
 
1164
{
-
 
1165
	NSInteger level = [sender tag];
-
 
1166
	NSInteger bracketCounter = 0;
-
 
1167
	NSInteger start = 0;
-
 
1168
	NSInteger end = 0;
-
 
1169
	CFStringRef str = (CFStringRef)[self string];
-
 
1170
	
-
 
1171
	unichar c;
-
 
1172
	
-
 
1173
	// [self unFoldAllBlocks:self];
-
 
1174
	
-
 
1175
	for(NSInteger i=0; i<[[self string] length]; i++) {
-
 
1176
		c = CFStringGetCharacterAtIndex(str, i);
-
 
1177
		if([self parserContextForPosition:i] != pcExpression) continue;
-
 
1178
		if(c == '{') {
-
 
1179
			bracketCounter++;
-
 
1180
			if([self foldStatusAtIndex:i] == 1) {
-
 
1181
				if(bracketCounter == level+1) {
-
 
1182
					start = i;
-
 
1183
				}
-
 
1184
			}
-
 
1185
			continue;
-
 
1186
		}
-
 
1187
		if(c == '}') {
-
 
1188
			bracketCounter--;
-
 
1189
			if([self foldStatusAtIndex:i] == 2) {
-
 
1190
				if(bracketCounter == level) {
-
 
1191
					end = i;
-
 
1192
					NSRange r = NSMakeRange(start, end - start+1);
-
 
1193
					if(![theTextStorage existsFoldedRange:r])
-
 
1194
						[self foldLinesInRange:r];
-
 
1195
				}
-
 
1196
				if(bracketCounter < 0) {
-
 
1197
					NSBeep();
-
 
1198
					return;
-
 
1199
				}
-
 
1200
			}
-
 
1201
		}
-
 
1202
	}
-
 
1203
	
-
 
1204
}
-
 
1205
 
-
 
1206
- (IBAction)unFoldAllBlocks:(id)sender
-
 
1207
{
-
 
1208
	[theTextStorage removeAllFoldedRanges];
-
 
1209
 
-
 
1210
	[self didChangeText];
-
 
1211
 
-
 
1212
	NSRange r = NSMakeRange(0, [[self string] length]);
-
 
1213
 
-
 
1214
	[theTextStorage fixAttributesInRange:r];
-
 
1215
	[theTextStorage fixAttachmentAttributeInRange:r];
-
 
1216
	[theTextStorage ensureAttributesAreFixedInRange:r];
-
 
1217
 
-
 
1218
 
-
 
1219
	if(lineNumberingEnabled)
-
 
1220
		[[[self enclosingScrollView] verticalRulerView] performSelector:@selector(refresh) withObject:nil afterDelay:0.0f];
-
 
1221
	
-
 
1222
	[NSObject cancelPreviousPerformRequestsWithTarget:self 
-
 
1223
							selector:@selector(doSyntaxHighlighting) 
-
 
1224
							object:nil];
-
 
1225
 
-
 
1226
	[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.0f];
-
 
1227
}
-
 
1228
 
-
 
1229
- (void)refoldLinesInRange:(NSRange)range
-
 
1230
{
985
	NSInteger foldId = [theTextStorage registerFoldedRange:range];
1231
	NSInteger foldId = [theTextStorage registerFoldedRange:range];
986
	NSInteger caretPosition = [self selectedRange].location;
-
 
987
	BOOL caretWasInsideFoldedRange = NO;
-
 
988
 
1232
 
989
	if(foldId < 0) {
1233
	if(foldId < 0) {
990
		NSBeep();
-
 
-
 
1234
		[RTooltip showWithObject:NLS(@"Maximum number of folded code fragments is reached.") atLocation:[NSEvent mouseLocation]];
991
		return;
1235
		return;
992
	}
1236
	}
993
 
1237
 
-
 
1238
	range.location++;
-
 
1239
	range.length -= 2;
-
 
1240
 
-
 
1241
	if(!range.length) return;
-
 
1242
	
-
 
1243
	NSString *tooltip = nil;
-
 
1244
	if(range.length < 300)
994
	if(caretPosition >= range.location && caretPosition < NSMaxRange(range)) {
1245
		tooltip = [[self string] substringWithRange:range];
-
 
1246
	else
-
 
1247
		tooltip = [[[self string] substringWithRange:NSMakeRange(range.location, 300)] stringByAppendingString:@"\n…"];
-
 
1248
 
-
 
1249
	[theTextStorage beginEditing];
-
 
1250
	[theTextStorage addAttribute:NSCursorAttributeName value:[NSCursor arrowCursor] range:range];
-
 
1251
	[theTextStorage addAttribute:NSToolTipAttributeName value:tooltip range:range];
-
 
1252
	[theTextStorage endEditing];
-
 
1253
 
-
 
1254
}
-
 
1255
 
995
		[self setSelectedRange:NSMakeRange(NSMaxRange(range), 0)];
1256
- (BOOL)foldLinesInRange:(NSRange)range
-
 
1257
{
996
		caretWasInsideFoldedRange = YES;
1258
	if(range.length < 5) {
-
 
1259
		return NO;
997
	}
1260
	}
998
 
1261
 
999
	unichar s = [[self string] characterAtIndex:range.location];
1262
	NSInteger caretPosition = [self selectedRange].location;
-
 
1263
	BOOL caretWasInsideFoldedRange = NO;
-
 
1264
 
-
 
1265
	// Check for valid folding range
1000
	unichar e = [[self string] characterAtIndex:NSMaxRange(range)-1];
1266
	// fold only range if { and } are the last chars at the line
1001
 
1267
 
1002
	BOOL wrapCheck = NO;
1268
	NSString *selfStr = [self string];
-
 
1269
	NSRange startLineRange = [selfStr lineRangeForRange:NSMakeRange(range.location, 0)];
-
 
1270
	NSRange endLineRange   = [selfStr lineRangeForRange:NSMakeRange(NSMaxRange(range), 0)];
1003
 
1271
 
1004
	if(s == '{' && e == '}') {
-
 
1005
		range.location++;
-
 
1006
		range.length -= 2;
-
 
1007
		wrapCheck = YES;
-
 
1008
	} else if(s == '(' && e == ')') {
1272
	if(!startLineRange.length || !endLineRange.length) {
1009
		range.location++;
-
 
1010
		range.length -= 2;
-
 
1011
		wrapCheck = YES;
-
 
1012
	} else if(s == '[' && e == ']') {
-
 
1013
		range.location++;
-
 
1014
		range.length -= 2;
-
 
1015
		wrapCheck = YES;
1273
		return NO;
1016
	}
1274
	}
1017
 
1275
 
1018
	if(!range.length) return;
1276
	// Do not fold a single line
-
 
1277
	if(startLineRange.location == endLineRange.location) {
-
 
1278
		return NO;
-
 
1279
	}
1019
 
1280
 
1020
	if(!wrapCheck && [[self string] characterAtIndex:NSMaxRange(range)-1] == '\n')
-
 
1021
		range.length--;
1281
	NSInteger status;
1022
 
1282
 
-
 
1283
	status = [self foldStatusAtIndex:NSMaxRange(startLineRange)-2];	
1023
	if(!range.length) return;
1284
	if(status != 1) {
-
 
1285
		return NO;
-
 
1286
	}
1024
 
1287
 
-
 
1288
	unichar c = CFStringGetCharacterAtIndex((CFStringRef)selfStr, NSMaxRange(endLineRange)-1);
-
 
1289
	if(c == '\n' || c == '\r')
-
 
1290
		status = [self foldStatusAtIndex:NSMaxRange(endLineRange)-2];
-
 
1291
	else
-
 
1292
		status = [self foldStatusAtIndex:NSMaxRange(endLineRange)-1];	
-
 
1293
	if(status != 2) {
-
 
1294
		return NO;
-
 
1295
	}
-
 
1296
 
-
 
1297
	if(caretPosition >= range.location && caretPosition < NSMaxRange(range)) {
-
 
1298
		[self setSelectedRange:NSMakeRange(NSMaxRange(range), 0)];
-
 
1299
		caretWasInsideFoldedRange = YES;
-
 
1300
	}
-
 
1301
 
-
 
1302
	NSInteger foldId = [theTextStorage registerFoldedRange:range];
-
 
1303
 
-
 
1304
	if(foldId < 0) {
-
 
1305
		[RTooltip showWithObject:NLS(@"Maximum number of folded code fragments is reached.") atLocation:[NSEvent mouseLocation]];
-
 
1306
		return NO;
-
 
1307
	}
-
 
1308
 
-
 
1309
	range.location++;
-
 
1310
	range.length -= 2;
-
 
1311
 
-
 
1312
	if(!range.length) return NO;
-
 
1313
	
-
 
1314
	[[self undoManager] disableUndoRegistration];
-
 
1315
	if(![self shouldChangeTextInRange:range replacementString:nil]) {
-
 
1316
		[[self undoManager] enableUndoRegistration];
-
 
1317
		return NO;
-
 
1318
	}
-
 
1319
	[[self undoManager] enableUndoRegistration];
1025
 
1320
 
1026
	NSString *tooltip = nil;
1321
	NSString *tooltip = nil;
1027
	if(range.length < 300)
1322
	if(range.length < 300)
1028
		tooltip = [[self string] substringWithRange:range];
1323
		tooltip = [[self string] substringWithRange:range];
1029
	else
1324
	else
1030
		tooltip = [[[self string] substringWithRange:NSMakeRange(range.location, 300)] stringByAppendingString:@"\n…"];
1325
		tooltip = [[[self string] substringWithRange:NSMakeRange(range.location, 300)] stringByAppendingString:@"\n…"];
1031
 
1326
 
1032
	[theTextStorage beginEditing];
1327
	[theTextStorage beginEditing];
1033
	[theTextStorage addAttribute:foldingAttributeId value:[NSNumber numberWithInteger:foldId] range:range];
-
 
1034
	[theTextStorage addAttribute:NSCursorAttributeName value:[NSCursor arrowCursor] range:range];
1328
	[theTextStorage addAttribute:NSCursorAttributeName value:[NSCursor arrowCursor] range:range];
1035
	[theTextStorage addAttribute:NSToolTipAttributeName value:tooltip range:range];
1329
	[theTextStorage addAttribute:NSToolTipAttributeName value:tooltip range:range];
1036
	[theTextStorage endEditing];
1330
	[theTextStorage endEditing];
1037
 
1331
 
1038
	[self didChangeText];
1332
	[self didChangeText];
1039
 
1333
 
1040
	if(caretWasInsideFoldedRange)
1334
	if(caretWasInsideFoldedRange)
1041
		[self scrollRangeToVisible:[self selectedRange]];
1335
		[self scrollRangeToVisible:[self selectedRange]];
1042
 
1336
 
-
 
1337
	NSRange r = [[self layoutManager] characterRangeForGlyphRange:[[self layoutManager] 
-
 
1338
										glyphRangeForBoundingRect:[scrollView documentVisibleRect] 
-
 
1339
												  inTextContainer:[self textContainer]] actualGlyphRange:NULL];
-
 
1340
 
-
 
1341
	[theTextStorage ensureAttributesAreFixedInRange:r];
-
 
1342
 
1043
	if(lineNumberingEnabled)
1343
	if(lineNumberingEnabled)
1044
		[[[self enclosingScrollView] verticalRulerView] performSelector:@selector(refresh) withObject:nil afterDelay:0.01f];
1344
		[[[self enclosingScrollView] verticalRulerView] performSelector:@selector(refresh) withObject:nil afterDelay:0.0f];
1045
	
1345
	
1046
	[NSObject cancelPreviousPerformRequestsWithTarget:self 
1346
	[NSObject cancelPreviousPerformRequestsWithTarget:self 
1047
							selector:@selector(doSyntaxHighlighting) 
1347
							selector:@selector(doSyntaxHighlighting) 
1048
							object:nil];
1348
							object:nil];
1049
	[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.0f];
-
 
1050
 
1349
 
-
 
1350
	[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.02f];
-
 
1351
 
-
 
1352
	return YES;
-
 
1353
 
-
 
1354
}
-
 
1355
 
-
 
1356
- (NSInteger)foldStatusAtIndex:(NSInteger)index
-
 
1357
{
-
 
1358
 
-
 
1359
	if(index < 0 || index >= [[self string] length]) return 0;
-
 
1360
 
-
 
1361
	NSInteger status = 0; // 0 = no; 1 = ▼; 2 = ▲
-
 
1362
 
-
 
1363
	NSInteger i = index;
-
 
1364
	NSInteger type;
-
 
1365
	NSString *selfStr = [self string];
-
 
1366
	unichar c;
-
 
1367
 
-
 
1368
	BOOL isRd = [[self delegate] isRdDocument];
-
 
1369
 
-
 
1370
	unichar commentSign = (isRd) ? '%' : '#';
-
 
1371
 
-
 
1372
	// start checking from the end of a line
-
 
1373
	while(i >= 0) {
-
 
1374
 
-
 
1375
		c = CFStringGetCharacterAtIndex((CFStringRef)selfStr, i);
-
 
1376
 
-
 
1377
		// Check only one line
-
 
1378
		if(c=='\n' || c=='\r') break;
-
 
1379
 
-
 
1380
		// Ignore white spaces and comment sign
-
 
1381
		if(c==' ' || c=='\t' || c==commentSign) {
-
 
1382
			i--;
-
 
1383
			continue;
-
 
1384
		}
-
 
1385
 
-
 
1386
		type = [self parserContextForPosition:i];
-
 
1387
 
-
 
1388
		// Ignore comments
-
 
1389
		if(type == pcComment || c==commentSign) {
-
 
1390
			i--;
-
 
1391
			continue;
-
 
1392
		}
-
 
1393
 
-
 
1394
		// ======= Check for ▼ 
-
 
1395
		if(c=='{' && type == pcExpression) {
-
 
1396
			status = 1;
-
 
1397
			// look for lines a la "} else {" - if so do not draw folding marker
-
 
1398
			i--;
-
 
1399
			while(i>=0) {
-
 
1400
				c = CFStringGetCharacterAtIndex((CFStringRef)selfStr, i);
-
 
1401
				if(c=='\n' || c=='\r') break;
-
 
1402
				if((c=='}' || c=='{')&& [self parserContextForPosition:i] == pcExpression) {
-
 
1403
					status = 0;
-
 
1404
					break;
-
 
1405
				}
-
 
1406
				i--;
-
 
1407
			}
-
 
1408
			break;
-
 
1409
		}
-
 
1410
 
-
 
1411
		// ======= Check for ▲
-
 
1412
		if(c=='}') {
-
 
1413
			status = 2;
-
 
1414
			i--;
-
 
1415
			while(i>=0) {
-
 
1416
				c = CFStringGetCharacterAtIndex((CFStringRef)selfStr, i);
-
 
1417
				if(c=='\n' || c=='\r') break;
-
 
1418
				if((c=='}' || c=='{')&& [self parserContextForPosition:i] == pcExpression) {
-
 
1419
					status = 0;
-
 
1420
					break;
-
 
1421
				}
-
 
1422
				if(isRd) {
-
 
1423
					if(c != '\t' || c != ' ') {
-
 
1424
						status = 0;
-
 
1425
						break;
-
 
1426
					}
-
 
1427
				}
-
 
1428
				i--;
-
 
1429
			}
-
 
1430
		}
-
 
1431
		break;
-
 
1432
 
-
 
1433
	}
-
 
1434
 
-
 
1435
	return status;
-
 
1436
	
1051
}
1437
}
1052
 
1438
 
1053
- (BOOL)unfoldLinesContainingCharacterAtIndex:(NSUInteger)charIndex
1439
- (BOOL)unfoldLinesContainingCharacterAtIndex:(NSUInteger)charIndex
1054
{
1440
{
1055
 
1441
 
1056
	NSInteger foldIndex = [theTextStorage foldedAtIndex:charIndex];
1442
	NSInteger foldIndex = [theTextStorage foldedAtIndex:charIndex];
1057
 
1443
 
1058
	if(foldIndex > -1) {
1444
	if(foldIndex > -1) {
-
 
1445
 
-
 
1446
		NSRange range = [theTextStorage foldedRangeAtIndex:foldIndex];
-
 
1447
		[[self undoManager] disableUndoRegistration];
-
 
1448
		if(![self shouldChangeTextInRange:range replacementString:nil]) {
-
 
1449
			[[self undoManager] enableUndoRegistration];
-
 
1450
			return NO;
-
 
1451
		}
-
 
1452
		[[self undoManager] enableUndoRegistration];
-
 
1453
		
1059
		[theTextStorage removeFoldedRangeWithId:[theTextStorage attribute:foldingAttributeId atIndex:charIndex effectiveRange:NULL]];
1454
		[theTextStorage removeFoldedRangeWithIndex:foldIndex];
1060
 
1455
 
1061
		[self didChangeText];
1456
		[self didChangeText];
1062
 
1457
 
1063
		if(lineNumberingEnabled)
-
 
1064
			[[[self enclosingScrollView] verticalRulerView] performSelector:@selector(refresh) withObject:nil afterDelay:0.01f];
-
 
1065
		
-
 
1066
		[NSObject cancelPreviousPerformRequestsWithTarget:self 
1458
		[NSObject cancelPreviousPerformRequestsWithTarget:self 
1067
								selector:@selector(doSyntaxHighlighting) 
1459
								selector:@selector(doSyntaxHighlighting) 
1068
								object:nil];
1460
								object:nil];
1069
 
1461
 
-
 
1462
		NSRange r = [[self layoutManager] characterRangeForGlyphRange:[[self layoutManager] 
-
 
1463
											glyphRangeForBoundingRect:[scrollView documentVisibleRect] 
1070
		[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.0f];
1464
													  inTextContainer:[self textContainer]] actualGlyphRange:NULL];
1071
 
1465
 
-
 
1466
		[theTextStorage ensureAttributesAreFixedInRange:r];
-
 
1467
 
-
 
1468
		if(lineNumberingEnabled)
-
 
1469
			[[[self enclosingScrollView] verticalRulerView] performSelector:@selector(refresh) withObject:nil afterDelay:0.0f];
-
 
1470
		
-
 
1471
		[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.02f];
1072
 
1472
 
1073
		return YES;
1473
		return YES;
1074
	}
1474
	}
1075
	
1475
	
1076
	return NO;
1476
	return NO;
Line 1078... Line 1478...
1078
}
1478
}
1079
 
1479
 
1080
- (void)mouseDown:(NSEvent *)event
1480
- (void)mouseDown:(NSEvent *)event
1081
{
1481
{
1082
 
1482
 
-
 
1483
	if(![theTextStorage isKindOfClass:[RScriptEditorTextStorage class]]) {
-
 
1484
		[super mouseDown:event];
-
 
1485
		return;
-
 
1486
	}
-
 
1487
	
-
 
1488
	RScriptEditorLayoutManager *layoutManager = (RScriptEditorLayoutManager*)[self layoutManager];
-
 
1489
	NSUInteger glyphIndex = [layoutManager glyphIndexForPoint:[self convertPointFromBase:[event locationInWindow]] inTextContainer:[self textContainer]];
-
 
1490
	
1083
	// <TODO> enable for folding
1491
	// trigger unfolding if inside foldingAttachmentCell
-
 
1492
	if (glyphIndex < [layoutManager numberOfGlyphs]) {
-
 
1493
	
-
 
1494
		NSUInteger charIndex = [layoutManager characterIndexForGlyphAtIndex:glyphIndex];
-
 
1495
		NSInteger foldIndex  = [theTextStorage foldedForIndicatorAtIndex:charIndex];
-
 
1496
	
-
 
1497
		if (foldIndex > -1) {
-
 
1498
	
-
 
1499
			NSInteger foldStart = [theTextStorage foldedRangeAtIndex:foldIndex].location+1;
-
 
1500
			NSTextAttachment *attachment = [theTextStorage attribute:NSAttachmentAttributeName atIndex:foldStart effectiveRange:NULL];
-
 
1501
	
-
 
1502
			if (attachment) {
-
 
1503
				NSTextAttachmentCell *cell = (NSTextAttachmentCell *)[attachment attachmentCell];
-
 
1504
				NSRect cellFrame;
-
 
1505
				NSPoint delta;
-
 
1506
	
-
 
1507
				glyphIndex = [layoutManager glyphIndexForCharacterAtIndex:foldStart];
-
 
1508
	
-
 
1509
				cellFrame.origin = [self textContainerOrigin];
-
 
1510
				cellFrame.size = [layoutManager attachmentSizeForGlyphAtIndex:glyphIndex];
-
 
1511
	
-
 
1512
				delta = [layoutManager lineFragmentRectForGlyphAtIndex:glyphIndex effectiveRange:NULL].origin;
-
 
1513
				cellFrame.origin.x += delta.x;
-
 
1514
				cellFrame.origin.y += delta.y;
-
 
1515
	
-
 
1516
				cellFrame.origin.x += [layoutManager locationForGlyphAtIndex:glyphIndex].x;
-
 
1517
	
-
 
1518
				if ([cell wantsToTrackMouseForEvent:event inRect:cellFrame ofView:self atCharacterIndex:foldStart] 
-
 
1519
						&& [cell trackMouse:event inRect:cellFrame ofView:self atCharacterIndex:foldStart untilMouseUp:YES]) return;
-
 
1520
			}
-
 
1521
		}
-
 
1522
	}
-
 
1523
	
1084
	[super mouseDown:event];
1524
	[super mouseDown:event];
1085
 
-
 
1086
	// if(![theTextStorage isKindOfClass:[RScriptEditorTextStorage class]]) {
-
 
1087
	// 	[super mouseDown:event];
-
 
1088
	// 	return;
-
 
1089
	// }
-
 
1090
	// 
-
 
1091
	// RScriptEditorLayoutManager *layoutManager = (RScriptEditorLayoutManager*)[self layoutManager];
-
 
1092
	// NSUInteger glyphIndex = [layoutManager glyphIndexForPoint:[self convertPointFromBase:[event locationInWindow]] inTextContainer:[self textContainer]];
-
 
1093
	// 
-
 
1094
	// // trigger unfolding if inside foldingAttachmentCell
-
 
1095
	// if (glyphIndex < [layoutManager numberOfGlyphs]) {
-
 
1096
	// 
-
 
1097
	// 	NSUInteger charIndex = [layoutManager characterIndexForGlyphAtIndex:glyphIndex];
-
 
1098
	// 	NSInteger foldIndex  = [theTextStorage foldedForIndicatorAtIndex:charIndex];
-
 
1099
	// 
-
 
1100
	// 	if (foldIndex > -1) {
-
 
1101
	// 
-
 
1102
	// 		NSInteger foldStart = [theTextStorage foldedRangeAtIndex:foldIndex].location+1;
-
 
1103
	// 		NSTextAttachment *attachment = [theTextStorage attribute:NSAttachmentAttributeName atIndex:foldStart effectiveRange:NULL];
-
 
1104
	// 
-
 
1105
	// 		if (attachment) {
-
 
1106
	// 			NSTextAttachmentCell *cell = (NSTextAttachmentCell *)[attachment attachmentCell];
-
 
1107
	// 			NSRect cellFrame;
-
 
1108
	// 			NSPoint delta;
-
 
1109
	// 
-
 
1110
	// 			glyphIndex = [layoutManager glyphIndexForCharacterAtIndex:foldStart];
-
 
1111
	// 
-
 
1112
	// 			cellFrame.origin = [self textContainerOrigin];
-
 
1113
	// 			cellFrame.size = [layoutManager attachmentSizeForGlyphAtIndex:glyphIndex];
-
 
1114
	// 
-
 
1115
	// 			delta = [layoutManager lineFragmentRectForGlyphAtIndex:glyphIndex effectiveRange:NULL].origin;
-
 
1116
	// 			cellFrame.origin.x += delta.x;
-
 
1117
	// 			cellFrame.origin.y += delta.y;
-
 
1118
	// 
-
 
1119
	// 			cellFrame.origin.x += [layoutManager locationForGlyphAtIndex:glyphIndex].x;
-
 
1120
	// 
-
 
1121
	// 			if ([cell wantsToTrackMouseForEvent:event inRect:cellFrame ofView:self atCharacterIndex:foldStart] 
-
 
1122
	// 					&& [cell trackMouse:event inRect:cellFrame ofView:self atCharacterIndex:foldStart untilMouseUp:YES]) return;
-
 
1123
	// 		}
-
 
1124
	// 	}
-
 
1125
	// }
-
 
1126
	// 
-
 
1127
	// [super mouseDown:event];
-
 
1128
}
1525
}
1129
 
1526
 
1130
// - (void)setSelectedRanges:(NSArray *)ranges affinity:(NSSelectionAffinity)affinity stillSelecting:(BOOL)stillSelectingFlag
1527
// - (void)setSelectedRanges:(NSArray *)ranges affinity:(NSSelectionAffinity)affinity stillSelecting:(BOOL)stillSelectingFlag
1131
// {
1528
// {
1132
// 
1529
// 
Line 1163... Line 1560...
1163
// 	[super setSelectedRanges:ranges affinity:affinity stillSelecting:stillSelectingFlag];
1560
// 	[super setSelectedRanges:ranges affinity:affinity stillSelecting:stillSelectingFlag];
1164
// 
1561
// 
1165
// }
1562
// }
1166
// 
1563
// 
1167
 
1564
 
1168
- (void)setTypingAttributes:(NSDictionary *)attrs
1565
// - (void)setTypingAttributes:(NSDictionary *)attrs
1169
{
1566
// {
1170
	// we don't want to store foldingAttributeId as a typing attribute
1567
// 	// we don't want to store foldingAttributeId as a typing attribute
1171
	if ([attrs objectForKey:foldingAttributeId]) {
1568
// 	if ([attrs objectForKey:foldingAttributeId]) {
1172
		NSMutableDictionary *copy = [[attrs mutableCopyWithZone:NULL] autorelease];
1569
// 		NSMutableDictionary *copy = [[attrs mutableCopyWithZone:NULL] autorelease];
1173
		[copy removeObjectForKey:foldingAttributeId];
1570
// 		[copy removeObjectForKey:foldingAttributeId];
1174
		attrs = copy;
1571
// 		attrs = copy;
1175
	}
1572
// 	}
1176
 
1573
// 
1177
	[super setTypingAttributes:attrs];
1574
// 	[super setTypingAttributes:attrs];
1178
}
1575
// }
1179
 
1576
// 
1180
#pragma mark -
1577
#pragma mark -
1181
 
1578
 
1182
- (void)updatePreferences
1579
- (void)updatePreferences
1183
{
1580
{
1184
	
1581
	
1185
}
1582
}
1186
@end
1583
@end
-
 
1584
 
-
 
1585