| Line 38... |
Line 38... |
| 38 |
#import "RScriptEditorTextStorage.h"
|
38 |
#import "RScriptEditorTextStorage.h"
|
| 39 |
#import "PreferenceKeys.h"
|
39 |
#import "PreferenceKeys.h"
|
| 40 |
|
40 |
|
| 41 |
@implementation RScriptEditorLayoutManager
|
41 |
@implementation RScriptEditorLayoutManager
|
| 42 |
|
42 |
|
| - |
|
43 |
static SEL _setfSel;
|
| - |
|
44 |
|
| 43 |
- (id)init
|
45 |
- (id)init
|
| 44 |
{
|
46 |
{
|
| 45 |
|
47 |
|
| 46 |
self = [super init];
|
48 |
self = [super init];
|
| 47 |
|
49 |
|
| Line 49... |
Line 51... |
| 49 |
|
51 |
|
| 50 |
// Setup LineFoldingTypesetter
|
52 |
// Setup LineFoldingTypesetter
|
| 51 |
RScriptEditorTypeSetter *typesetter = [[RScriptEditorTypeSetter alloc] init];
|
53 |
RScriptEditorTypeSetter *typesetter = [[RScriptEditorTypeSetter alloc] init];
|
| 52 |
[self setTypesetter:typesetter];
|
54 |
[self setTypesetter:typesetter];
|
| 53 |
[typesetter release];
|
55 |
[typesetter release];
|
| 54 |
|
56 |
|
| 55 |
// Setup LineFoldingGlyphGenerator
|
57 |
// Setup LineFoldingGlyphGenerator
|
| 56 |
RScriptEditorGlyphGenerator *glyphGenerator = [[RScriptEditorGlyphGenerator alloc] init];
|
58 |
RScriptEditorGlyphGenerator *glyphGenerator = [[RScriptEditorGlyphGenerator alloc] init];
|
| 57 |
[self setGlyphGenerator:glyphGenerator];
|
59 |
[self setGlyphGenerator:glyphGenerator];
|
| 58 |
[glyphGenerator release];
|
60 |
[glyphGenerator release];
|
| 59 |
|
61 |
|
| 60 |
[self setBackgroundLayoutEnabled:YES];
|
62 |
[self setBackgroundLayoutEnabled:YES];
|
| 61 |
|
63 |
|
| - |
|
64 |
_setfSel = @selector(setLineFoldingEnabled:);
|
| - |
|
65 |
|
| 62 |
return self;
|
66 |
return self;
|
| 63 |
|
67 |
|
| 64 |
}
|
68 |
}
|
| 65 |
|
69 |
|
| 66 |
- (void)drawGlyphsForGlyphRange:(NSRange)glyphsToShow atPoint:(NSPoint)origin
|
70 |
- (void)dealloc
|
| 67 |
{
|
71 |
{
|
| 68 |
// <SPEED>
|
- |
|
| 69 |
NSTextStorage *textStorage = [self textStorage];
|
72 |
if(_attributedString) [_attributedString release];
|
| 70 |
|
- |
|
| 71 |
[(RScriptEditorTextStorage *)textStorage setLineFoldingEnabled:YES];
|
- |
|
| 72 |
[super drawGlyphsForGlyphRange:glyphsToShow atPoint:origin];
|
73 |
[super dealloc];
|
| 73 |
[(RScriptEditorTextStorage *)textStorage setLineFoldingEnabled:NO];
|
- |
|
| 74 |
}
|
74 |
}
|
| 75 |
|
75 |
|
| 76 |
- (void)textStorage:(NSTextStorage *)str edited:(NSUInteger)editedMask range:(NSRange)newCharRange changeInLength:(NSInteger)delta invalidatedRange:(NSRange)invalidatedCharRange
|
76 |
- (void)replaceTextStorage:(id)textStorage
|
| 77 |
{
|
77 |
{
|
| 78 |
|
- |
|
| 79 |
NSUInteger length = [str length];
|
- |
|
| 80 |
NSNumber *value;
|
- |
|
| 81 |
NSRange effectiveRange, range;
|
- |
|
| 82 |
|
- |
|
| 83 |
// it's at the end. check if the last char is in foldingAttributeName
|
- |
|
| 84 |
if ((invalidatedCharRange.location == length) && (invalidatedCharRange.location != 0)) {
|
- |
|
| 85 |
value = [str attribute:foldingAttributeName atIndex:invalidatedCharRange.location - 1 effectiveRange:&effectiveRange];
|
- |
|
| 86 |
if (value && [value boolValue]) invalidatedCharRange = NSUnionRange(invalidatedCharRange, effectiveRange);
|
- |
|
| 87 |
}
|
- |
|
| 88 |
|
- |
|
| 89 |
if (invalidatedCharRange.location < length) {
|
- |
|
| 90 |
NSString *string = [str string];
|
78 |
if(_attributedString) [_attributedString release];
|
| 91 |
NSUInteger start, end;
|
- |
|
| 92 |
|
- |
|
| 93 |
if (delta > 0) {
|
- |
|
| 94 |
NSUInteger contentsEnd;
|
- |
|
| 95 |
[string getParagraphStart:NULL end:&end contentsEnd:&contentsEnd forRange:newCharRange];
|
79 |
_attributedString = [(RScriptEditorTextStorage*)textStorage retain];
|
| 96 |
if ((contentsEnd != end) && (invalidatedCharRange.location > 0)
|
- |
|
| 97 |
&& (NSMaxRange(newCharRange) == end)) {
|
- |
|
| 98 |
// there was para sep insertion. extend to both sides
|
80 |
_setfImp = [_attributedString methodForSelector:_setfSel];
|
| 99 |
if (newCharRange.location <= invalidatedCharRange.location) {
|
- |
|
| 100 |
invalidatedCharRange.length = (NSMaxRange(invalidatedCharRange) - (newCharRange.location - 1));
|
- |
|
| 101 |
invalidatedCharRange.location = (newCharRange.location - 1);
|
- |
|
| 102 |
}
|
- |
|
| 103 |
|
- |
|
| 104 |
if ((end < length) && (NSMaxRange(invalidatedCharRange) <= end)) {
|
- |
|
| 105 |
invalidatedCharRange.length = ((end + 1) - invalidatedCharRange.location);
|
- |
|
| 106 |
}
|
- |
|
| 107 |
}
|
- |
|
| 108 |
}
|
- |
|
| 109 |
|
- |
|
| 110 |
range = invalidatedCharRange;
|
- |
|
| 111 |
|
- |
|
| 112 |
while ((range.location > 0) || (NSMaxRange(range) < length)) {
|
- |
|
| 113 |
[string getParagraphStart:&start end:&end contentsEnd:NULL forRange:range];
|
81 |
[(RScriptEditorGlyphGenerator*)[self glyphGenerator] setTextStorage:textStorage];
|
| 114 |
range.location = start;
|
- |
|
| 115 |
range.length = (end - start);
|
- |
|
| 116 |
|
- |
|
| 117 |
// Extend backward
|
- |
|
| 118 |
value = [str attribute:foldingAttributeName atIndex:range.location longestEffectiveRange:&effectiveRange inRange:NSMakeRange(0, range.location + 1)];
|
- |
|
| 119 |
if (value && [value boolValue] && (effectiveRange.location < range.location)) {
|
- |
|
| 120 |
range.length += (range.location - effectiveRange.location);
|
- |
|
| 121 |
range.location = effectiveRange.location;
|
82 |
[super replaceTextStorage:textStorage];
|
| 122 |
}
|
- |
|
| 123 |
|
- |
|
| 124 |
// Extend forward
|
- |
|
| 125 |
if (NSMaxRange(range) < length) {
|
- |
|
| 126 |
value = [str attribute:foldingAttributeName atIndex:NSMaxRange(range) longestEffectiveRange:&effectiveRange inRange:NSMakeRange(NSMaxRange(range), length - NSMaxRange(range))];
|
- |
|
| 127 |
if (value && [value boolValue] && (NSMaxRange(effectiveRange) > NSMaxRange(range))) {
|
- |
|
| 128 |
range.length = NSMaxRange(effectiveRange) - range.location;
|
- |
|
| 129 |
}
|
- |
|
| 130 |
}
|
- |
|
| 131 |
|
- |
|
| 132 |
if (NSEqualRanges(range, invalidatedCharRange)) break;
|
- |
|
| 133 |
invalidatedCharRange = range;
|
- |
|
| 134 |
}
|
- |
|
| 135 |
}
|
- |
|
| 136 |
|
- |
|
| 137 |
[super textStorage:str edited:editedMask range:newCharRange changeInLength:delta invalidatedRange:invalidatedCharRange];
|
- |
|
| 138 |
|
- |
|
| 139 |
}
|
83 |
}
|
| 140 |
|
84 |
|
| - |
|
85 |
// - (void)drawGlyphsForGlyphRange:(NSRange)glyphsToShow atPoint:(NSPoint)origin
|
| - |
|
86 |
// {
|
| - |
|
87 |
// // (*_setfImp)(_attributedString, _setfSel, YES);
|
| - |
|
88 |
// [super drawGlyphsForGlyphRange:glyphsToShow atPoint:origin];
|
| - |
|
89 |
// // (*_setfImp)(_attributedString, _setfSel, NO);
|
| - |
|
90 |
// }
|
| - |
|
91 |
|
| - |
|
92 |
// - (void)textStorage:(RScriptEditorTextStorage *)str edited:(NSUInteger)editedMask range:(NSRange)newCharRange changeInLength:(NSInteger)delta invalidatedRange:(NSRange)invalidatedCharRange
|
| - |
|
93 |
// {
|
| - |
|
94 |
//
|
| - |
|
95 |
// NSUInteger length = [str length];
|
| - |
|
96 |
// // NSNumber *value;
|
| - |
|
97 |
// NSRange effectiveRange, range;
|
| - |
|
98 |
// NSInteger foldIndex;
|
| - |
|
99 |
//
|
| - |
|
100 |
// // it's at the end. check if the last char is in foldingAttributeName
|
| - |
|
101 |
// if ((invalidatedCharRange.location == length) && (invalidatedCharRange.location != 0)) {
|
| - |
|
102 |
// // value = [str attribute:foldingAttributeName atIndex:invalidatedCharRange.location - 1 effectiveRange:&effectiveRange];
|
| - |
|
103 |
// // if (value && [value boolValue]) invalidatedCharRange = NSUnionRange(invalidatedCharRange, effectiveRange);
|
| - |
|
104 |
// foldIndex = [str foldedForIndicatorAtIndex:invalidatedCharRange.location - 1];
|
| - |
|
105 |
// effectiveRange = [str foldedRangeAtIndex:foldIndex];
|
| - |
|
106 |
// effectiveRange.location++;
|
| - |
|
107 |
// effectiveRange.length-=2;
|
| - |
|
108 |
// if(foldIndex > -1) invalidatedCharRange = NSUnionRange(invalidatedCharRange, effectiveRange);
|
| - |
|
109 |
// }
|
| - |
|
110 |
//
|
| - |
|
111 |
// if (invalidatedCharRange.location < length) {
|
| - |
|
112 |
// NSString *string = [str string];
|
| - |
|
113 |
// NSUInteger start, end;
|
| - |
|
114 |
// if (delta > 0) {
|
| - |
|
115 |
// NSUInteger contentsEnd;
|
| - |
|
116 |
// [string getParagraphStart:NULL end:&end contentsEnd:&contentsEnd forRange:newCharRange];
|
| - |
|
117 |
// if ((contentsEnd != end) && (invalidatedCharRange.location > 0)
|
| - |
|
118 |
// && (NSMaxRange(newCharRange) == end)) {
|
| - |
|
119 |
// // there was para sep insertion. extend to both sides
|
| - |
|
120 |
// if (newCharRange.location <= invalidatedCharRange.location) {
|
| - |
|
121 |
// invalidatedCharRange.length = (NSMaxRange(invalidatedCharRange) - (newCharRange.location - 1));
|
| - |
|
122 |
// invalidatedCharRange.location = (newCharRange.location - 1);
|
| - |
|
123 |
// }
|
| - |
|
124 |
//
|
| - |
|
125 |
// if ((end < length) && (NSMaxRange(invalidatedCharRange) <= end)) {
|
| - |
|
126 |
// invalidatedCharRange.length = ((end + 1) - invalidatedCharRange.location);
|
| - |
|
127 |
// }
|
| - |
|
128 |
// }
|
| - |
|
129 |
// }
|
| - |
|
130 |
//
|
| - |
|
131 |
// range = invalidatedCharRange;
|
| - |
|
132 |
//
|
| - |
|
133 |
// while ((range.location > 0) || (NSMaxRange(range) < length)) {
|
| - |
|
134 |
// [string getParagraphStart:&start end:&end contentsEnd:NULL forRange:range];
|
| - |
|
135 |
// range.location = start;
|
| - |
|
136 |
// range.length = (end - start);
|
| - |
|
137 |
//
|
| - |
|
138 |
// // Extend backward
|
| - |
|
139 |
// foldIndex = [str foldedForIndicatorAtIndex:range.location];
|
| - |
|
140 |
// if(foldIndex > -1) {
|
| - |
|
141 |
// effectiveRange = [str foldedRangeAtIndex:foldIndex];
|
| - |
|
142 |
// if(effectiveRange.length) {
|
| - |
|
143 |
// // value = [str attribute:foldingAttributeName atIndex:range.location longestEffectiveRange:&effectiveRange inRange:NSMakeRange(0, range.location + 1)];
|
| - |
|
144 |
// // if (value && [value boolValue] && (effectiveRange.location < range.location)) {
|
| - |
|
145 |
// effectiveRange.location++;
|
| - |
|
146 |
// if (effectiveRange.location < range.location) {
|
| - |
|
147 |
// range.length += (range.location - effectiveRange.location);
|
| - |
|
148 |
// range.location = effectiveRange.location;
|
| - |
|
149 |
// }
|
| - |
|
150 |
// }
|
| - |
|
151 |
// }
|
| - |
|
152 |
// // Extend forward
|
| - |
|
153 |
// if (NSMaxRange(range) < length) {
|
| - |
|
154 |
// // value = [str attribute:foldingAttributeName atIndex:NSMaxRange(range) longestEffectiveRange:&effectiveRange inRange:NSMakeRange(NSMaxRange(range), length - NSMaxRange(range))];
|
| - |
|
155 |
// // if (value && [value boolValue] && (NSMaxRange(effectiveRange) > NSMaxRange(range))) {
|
| - |
|
156 |
// foldIndex = [str foldedForIndicatorAtIndex:NSMaxRange(range)];
|
| - |
|
157 |
// if(foldIndex > -1) {
|
| - |
|
158 |
// effectiveRange = [str foldedRangeAtIndex:foldIndex];
|
| - |
|
159 |
// if(effectiveRange.length) {
|
| - |
|
160 |
// effectiveRange.location++;
|
| - |
|
161 |
// effectiveRange.length-=2;
|
| - |
|
162 |
// if(NSMaxRange(effectiveRange) > NSMaxRange(range)) {
|
| - |
|
163 |
// range.length = NSMaxRange(effectiveRange) - range.location;
|
| - |
|
164 |
// }
|
| - |
|
165 |
// }
|
| - |
|
166 |
// }
|
| - |
|
167 |
// }
|
| - |
|
168 |
//
|
| - |
|
169 |
// if (NSEqualRanges(range, invalidatedCharRange)) break;
|
| - |
|
170 |
// invalidatedCharRange = range;
|
| - |
|
171 |
// }
|
| - |
|
172 |
// }
|
| - |
|
173 |
//
|
| - |
|
174 |
// [super textStorage:str edited:editedMask range:newCharRange changeInLength:delta invalidatedRange:invalidatedCharRange];
|
| - |
|
175 |
//
|
| - |
|
176 |
// }
|
| - |
|
177 |
|
| 141 |
@end
|
178 |
@end
|