| 6128 |
bibiko |
1 |
/*
|
|
|
2 |
* R.app : a Cocoa front end to: "R A Computer Language for Statistical Data Analysis"
|
|
|
3 |
*
|
|
|
4 |
* R.app Copyright notes:
|
|
|
5 |
* Copyright (C) 2004-12 The R Foundation
|
|
|
6 |
* written by Stefano M. Iacus and Simon Urbanek
|
|
|
7 |
*
|
|
|
8 |
*
|
|
|
9 |
* R Copyright notes:
|
|
|
10 |
* Copyright (C) 1995-1996 Robert Gentleman and Ross Ihaka
|
|
|
11 |
* Copyright (C) 1998-2001 The R Development Core Team
|
|
|
12 |
* Copyright (C) 2002-2004 The R Foundation
|
|
|
13 |
*
|
|
|
14 |
* This program is free software; you can redistribute it and/or modify
|
|
|
15 |
* it under the terms of the GNU General Public License as published by
|
|
|
16 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
17 |
* (at your option) any later version.
|
|
|
18 |
*
|
|
|
19 |
* This program is distributed in the hope that it will be useful,
|
|
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
22 |
* GNU General Public License for more details.
|
|
|
23 |
*
|
|
|
24 |
* A copy of the GNU General Public License is available via WWW at
|
|
|
25 |
* http://www.gnu.org/copyleft/gpl.html. You can also obtain it by
|
|
|
26 |
* writing to the Free Software Foundation, Inc., 59 Temple Place,
|
|
|
27 |
* Suite 330, Boston, MA 02111-1307 USA.
|
|
|
28 |
*
|
|
|
29 |
* RScriptEditorTextStorage.m
|
|
|
30 |
*
|
|
|
31 |
* Created by Hans-J. Bibiko on 01/03/2012.
|
|
|
32 |
*
|
|
|
33 |
*/
|
|
|
34 |
|
|
|
35 |
#import "RScriptEditorTextStorage.h"
|
| 7929 |
urbaneks |
36 |
#import "RScriptEditorTypeSetter.h"
|
| 6238 |
bibiko |
37 |
#import "RScriptEditorTextView.h"
|
| 6128 |
bibiko |
38 |
#import "FoldingSignTextAttachmentCell.h"
|
| 6238 |
bibiko |
39 |
#import "RGUI.h"
|
| 6128 |
bibiko |
40 |
|
|
|
41 |
@implementation RScriptEditorTextStorage
|
|
|
42 |
|
|
|
43 |
static NSTextAttachment *sharedAttachment = nil;
|
| 6137 |
bibiko |
44 |
static SEL _getSel;
|
|
|
45 |
static SEL _setSel;
|
| 6232 |
bibiko |
46 |
static SEL _strSel;
|
|
|
47 |
static SEL _replSel;
|
|
|
48 |
static SEL _editSel;
|
| 6233 |
bibiko |
49 |
static SEL _getlSel;
|
| 6128 |
bibiko |
50 |
|
|
|
51 |
+ (void)initialize
|
|
|
52 |
{
|
|
|
53 |
|
|
|
54 |
if ([self class] == [RScriptEditorTextStorage class]) {
|
|
|
55 |
FoldingSignTextAttachmentCell *cell = [[FoldingSignTextAttachmentCell alloc] initImageCell:nil];
|
|
|
56 |
sharedAttachment = [[NSTextAttachment alloc] init];
|
|
|
57 |
[sharedAttachment setAttachmentCell:cell];
|
|
|
58 |
[cell release];
|
| 6232 |
bibiko |
59 |
_getSel = @selector(attributesAtIndex:effectiveRange:);
|
|
|
60 |
_setSel = @selector(setAttributes:range:);
|
|
|
61 |
_strSel = @selector(string);
|
|
|
62 |
_replSel = @selector(replaceCharactersInRange:withString:);
|
|
|
63 |
_editSel = @selector(edited:range:changeInLength:);
|
| 6233 |
bibiko |
64 |
_getlSel = @selector(attribute:atIndex:longestEffectiveRange:inRange:);
|
|
|
65 |
|
| 6128 |
bibiko |
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
+ (NSTextAttachment *)attachment
|
|
|
70 |
{
|
|
|
71 |
return sharedAttachment;
|
|
|
72 |
}
|
|
|
73 |
|
| 6249 |
bibiko |
74 |
- (id)initWithDelegate:(id)theDelegate
|
| 6128 |
bibiko |
75 |
{
|
|
|
76 |
self = [super init];
|
|
|
77 |
|
|
|
78 |
if (self != nil) {
|
|
|
79 |
_attributedString = [[NSTextStorage alloc] init];
|
| 6233 |
bibiko |
80 |
|
| 6249 |
bibiko |
81 |
selfDelegate = (RScriptEditorTextView*)theDelegate;
|
|
|
82 |
[self setDelegate:theDelegate];
|
| 6233 |
bibiko |
83 |
foldedCounter = 0;
|
| 6238 |
bibiko |
84 |
currentMaxFoldedIndex = -1;
|
| 6233 |
bibiko |
85 |
|
|
|
86 |
for(NSInteger i = 0; i < R_MAX_FOLDED_ITEMS; i++) {
|
|
|
87 |
foldedRanges[i][0] = -1;
|
|
|
88 |
foldedRanges[i][1] = 0;
|
| 6238 |
bibiko |
89 |
foldedRanges[i][2] = 0;
|
| 6233 |
bibiko |
90 |
}
|
| 6128 |
bibiko |
91 |
}
|
|
|
92 |
|
|
|
93 |
return self;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
- (void)dealloc
|
|
|
97 |
{
|
|
|
98 |
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
99 |
[_attributedString release];
|
| 6232 |
bibiko |
100 |
if(sharedAttachment) [sharedAttachment release];
|
| 6128 |
bibiko |
101 |
[super dealloc];
|
|
|
102 |
}
|
|
|
103 |
|
| 6233 |
bibiko |
104 |
- (BOOL)hasFoldedItems
|
|
|
105 |
{
|
|
|
106 |
return (foldedCounter == 0) ? NO : YES;
|
|
|
107 |
}
|
|
|
108 |
|
| 6238 |
bibiko |
109 |
- (BOOL)inFoldedRangeForRange:(NSRange)range
|
|
|
110 |
{
|
|
|
111 |
if(!foldedCounter) return NO;
|
|
|
112 |
|
|
|
113 |
NSInteger i = 0;
|
|
|
114 |
NSInteger maxRange = NSMaxRange(range);
|
|
|
115 |
NSInteger rangeLoc = range.location;
|
|
|
116 |
for(i = 0; i < currentMaxFoldedIndex+1; i++) {
|
|
|
117 |
if(rangeLoc > foldedRanges[i][0] && maxRange <= foldedRanges[i][2]) {
|
|
|
118 |
return YES;
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
return NO;
|
|
|
122 |
|
|
|
123 |
}
|
|
|
124 |
|
| 6233 |
bibiko |
125 |
- (NSInteger)foldedAtIndex:(NSInteger)index
|
|
|
126 |
{
|
|
|
127 |
|
|
|
128 |
if(!foldedCounter) return -1;
|
|
|
129 |
|
|
|
130 |
NSInteger i = 0;
|
| 6238 |
bibiko |
131 |
for(i = 0; i < currentMaxFoldedIndex+1; i++) {
|
|
|
132 |
if(foldedRanges[i][2] > index && foldedRanges[i][0] <= index) {
|
| 6233 |
bibiko |
133 |
return i;
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
return -1;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
- (NSInteger)foldedForIndicatorAtIndex:(NSInteger)index
|
|
|
140 |
{
|
|
|
141 |
|
|
|
142 |
if(!foldedCounter) return -1;
|
|
|
143 |
|
|
|
144 |
if(index) {
|
|
|
145 |
// Folded ranges are stored from { to } but indicator will drawn inside of { and }
|
| 6238 |
bibiko |
146 |
NSInteger adjIndex = index + 1;
|
|
|
147 |
for(NSInteger i = 0; i < currentMaxFoldedIndex+1; i++) {
|
|
|
148 |
if(foldedRanges[i][2] > adjIndex && foldedRanges[i][0] < index) {
|
| 6233 |
bibiko |
149 |
return i;
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
}
|
|
|
153 |
return -1;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
- (NSInteger)registerFoldedRange:(NSRange)range
|
|
|
157 |
{
|
|
|
158 |
|
| 6238 |
bibiko |
159 |
|
| 6248 |
bibiko |
160 |
[[selfDelegate undoManager] disableUndoRegistration];
|
| 6238 |
bibiko |
161 |
|
| 6233 |
bibiko |
162 |
NSInteger index = -1;
|
|
|
163 |
for(NSInteger i = 0; i < R_MAX_FOLDED_ITEMS; i++) {
|
|
|
164 |
if(foldedRanges[i][0] == -1) {
|
|
|
165 |
index = i;
|
|
|
166 |
foldedRanges[i][0] = (NSInteger)range.location;
|
|
|
167 |
foldedRanges[i][1] = (NSInteger)range.length;
|
| 6238 |
bibiko |
168 |
foldedRanges[i][2] = (NSInteger)NSMaxRange(range);
|
| 6233 |
bibiko |
169 |
foldedCounter++;
|
| 6238 |
bibiko |
170 |
if(i > currentMaxFoldedIndex) currentMaxFoldedIndex = i;
|
| 7929 |
urbaneks |
171 |
SLog(@"RScriptEditorTextStorage:registerFoldedRange %@ at position %ld : max index %ld", NSStringFromRange(range), (long)i, (long)currentMaxFoldedIndex);
|
| 6233 |
bibiko |
172 |
break;
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
|
| 6248 |
bibiko |
176 |
[[selfDelegate undoManager] enableUndoRegistration];
|
| 6238 |
bibiko |
177 |
|
| 6233 |
bibiko |
178 |
return(index);
|
|
|
179 |
|
|
|
180 |
}
|
|
|
181 |
|
| 6238 |
bibiko |
182 |
- (BOOL)removeFoldedRangeWithIndex:(NSInteger)index
|
| 6233 |
bibiko |
183 |
{
|
|
|
184 |
|
| 6238 |
bibiko |
185 |
BOOL exists = NO;
|
|
|
186 |
NSRange range;
|
|
|
187 |
|
| 7929 |
urbaneks |
188 |
SLog(@"RScriptEditorTextStorage:removeFoldedRangeWithIndex %ld", (long)index);
|
| 6238 |
bibiko |
189 |
|
|
|
190 |
if(index > -1 && index < R_MAX_FOLDED_ITEMS) {
|
|
|
191 |
if(foldedRanges[index][0] > -1 && foldedRanges[index][1] > 0) {
|
|
|
192 |
range = NSMakeRange(foldedRanges[index][0], foldedRanges[index][1]);
|
|
|
193 |
exists = YES;
|
|
|
194 |
}
|
|
|
195 |
}
|
| 6233 |
bibiko |
196 |
|
| 6238 |
bibiko |
197 |
if(!exists) {
|
| 6233 |
bibiko |
198 |
[self removeAllFoldedRanges];
|
| 6238 |
bibiko |
199 |
NSLog(@"Removing folded text chunk failed. For safety reasons all folded chunks were be unfolded.");
|
| 6233 |
bibiko |
200 |
return NO;
|
|
|
201 |
}
|
|
|
202 |
|
| 6248 |
bibiko |
203 |
[[selfDelegate undoManager] disableUndoRegistration];
|
| 6233 |
bibiko |
204 |
|
| 6238 |
bibiko |
205 |
range = NSIntersectionRange(NSMakeRange(0, [[_attributedString string] length]), range);
|
| 6233 |
bibiko |
206 |
if(range.length) {
|
|
|
207 |
[self removeAttribute:NSCursorAttributeName range:range];
|
|
|
208 |
[self removeAttribute:NSToolTipAttributeName range:range];
|
|
|
209 |
}
|
|
|
210 |
|
| 6238 |
bibiko |
211 |
foldedRanges[index][0] = -1;
|
|
|
212 |
foldedRanges[index][1] = 0;
|
|
|
213 |
foldedRanges[index][2] = 0;
|
| 6233 |
bibiko |
214 |
foldedCounter--;
|
|
|
215 |
if(foldedCounter < 0) foldedCounter = 0;
|
|
|
216 |
|
| 6238 |
bibiko |
217 |
// check folded chunks inside range
|
|
|
218 |
NSInteger rloc = range.location;
|
|
|
219 |
NSInteger maxrlen = NSMaxRange(range);
|
|
|
220 |
NSRange r;
|
|
|
221 |
for(NSInteger j = currentMaxFoldedIndex; j >= 0; j--) {
|
|
|
222 |
if(foldedRanges[j][0] > rloc && foldedRanges[j][2] < maxrlen) {
|
|
|
223 |
r = NSMakeRange(foldedRanges[j][0], foldedRanges[j][1]);
|
|
|
224 |
foldedRanges[j][0] = -1;
|
|
|
225 |
foldedRanges[j][1] = 0;
|
|
|
226 |
foldedRanges[j][2] = 0;
|
| 6248 |
bibiko |
227 |
[selfDelegate refoldLinesInRange:r];
|
| 6238 |
bibiko |
228 |
}
|
|
|
229 |
}
|
|
|
230 |
|
| 6248 |
bibiko |
231 |
[[selfDelegate undoManager] enableUndoRegistration];
|
| 6238 |
bibiko |
232 |
|
|
|
233 |
// update currentMaxFoldedIndex
|
|
|
234 |
NSInteger maxCount = -1;
|
|
|
235 |
for(NSInteger i = 0; i < R_MAX_FOLDED_ITEMS; i++) {
|
|
|
236 |
if(foldedRanges[i][0] > -1) {
|
|
|
237 |
if(i > maxCount) maxCount = i;
|
|
|
238 |
}
|
|
|
239 |
}
|
|
|
240 |
currentMaxFoldedIndex = maxCount;
|
| 7929 |
urbaneks |
241 |
SLog(@"RScriptEditorTextStorage:removeFoldedRangeWithIndex: done. Max index: %ld", (long) currentMaxFoldedIndex);
|
| 6233 |
bibiko |
242 |
|
|
|
243 |
return YES;
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
- (void)removeAllFoldedRanges
|
|
|
247 |
{
|
| 6238 |
bibiko |
248 |
|
| 6248 |
bibiko |
249 |
[[selfDelegate undoManager] disableUndoRegistration];
|
| 6238 |
bibiko |
250 |
|
| 6233 |
bibiko |
251 |
for(NSInteger i = 0; i < R_MAX_FOLDED_ITEMS; i++) {
|
|
|
252 |
foldedRanges[i][0] = -1;
|
|
|
253 |
foldedRanges[i][1] = 0;
|
| 6238 |
bibiko |
254 |
foldedRanges[i][2] = 0;
|
| 6233 |
bibiko |
255 |
}
|
|
|
256 |
NSRange range = NSMakeRange(0, [_attributedString length]);
|
|
|
257 |
[self removeAttribute:NSCursorAttributeName range:range];
|
|
|
258 |
[self removeAttribute:NSToolTipAttributeName range:range];
|
| 6238 |
bibiko |
259 |
|
|
|
260 |
foldedCounter = 0;
|
|
|
261 |
currentMaxFoldedIndex = -1;
|
|
|
262 |
|
| 6248 |
bibiko |
263 |
[[selfDelegate undoManager] enableUndoRegistration];
|
| 6238 |
bibiko |
264 |
|
| 6233 |
bibiko |
265 |
}
|
|
|
266 |
|
|
|
267 |
- (BOOL)existsFoldedRange:(NSRange)range
|
|
|
268 |
{
|
|
|
269 |
|
|
|
270 |
if(!foldedCounter) return NO;
|
|
|
271 |
|
|
|
272 |
BOOL success = NO;
|
| 6238 |
bibiko |
273 |
for(NSInteger i = 0; i < currentMaxFoldedIndex+1; i++) {
|
| 6233 |
bibiko |
274 |
if(foldedRanges[i][0] == range.location && foldedRanges[i][1] == range.length) {
|
|
|
275 |
success = YES;
|
|
|
276 |
break;
|
|
|
277 |
}
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
return success;
|
|
|
281 |
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
- (NSRange)foldedRangeAtIndex:(NSInteger)index
|
|
|
285 |
{
|
|
|
286 |
|
|
|
287 |
if(!foldedCounter || index < 0 || index > R_MAX_FOLDED_ITEMS) return NSMakeRange(NSNotFound, 0);
|
|
|
288 |
|
|
|
289 |
NSInteger loc = foldedRanges[index][0];
|
| 6238 |
bibiko |
290 |
|
| 6233 |
bibiko |
291 |
if(loc == -1) return NSMakeRange(NSNotFound, 0);
|
| 6238 |
bibiko |
292 |
|
| 6246 |
bibiko |
293 |
return NSMakeRange(loc, foldedRanges[index][1]);
|
| 6238 |
bibiko |
294 |
|
| 6233 |
bibiko |
295 |
}
|
| 6238 |
bibiko |
296 |
#pragma mark -
|
|
|
297 |
#pragma mark Primitives
|
| 6233 |
bibiko |
298 |
|
| 6128 |
bibiko |
299 |
- (NSString *)string
|
|
|
300 |
{
|
| 7916 |
urbaneks |
301 |
return _attributedString ? [_attributedString string] : nil;
|
| 6128 |
bibiko |
302 |
}
|
|
|
303 |
|
|
|
304 |
- (NSDictionary *)attributesAtIndex:(NSUInteger)location effectiveRange:(NSRangePointer)range
|
|
|
305 |
{
|
|
|
306 |
|
| 7916 |
urbaneks |
307 |
NSDictionary *attributes = [_attributedString attributesAtIndex:location effectiveRange:range];
|
| 6128 |
bibiko |
308 |
|
| 6246 |
bibiko |
309 |
if(!foldedCounter || location > [_attributedString length]) return attributes;
|
| 6128 |
bibiko |
310 |
|
| 6137 |
bibiko |
311 |
NSRange effectiveRange;
|
| 6128 |
bibiko |
312 |
|
| 6233 |
bibiko |
313 |
// Check if location is inside folded range for drawing indicator
|
|
|
314 |
NSInteger index = -1;
|
|
|
315 |
if(location) {
|
|
|
316 |
// Notes folded ranges are stored from { to } but indicator will drawn inside of { and }
|
| 6238 |
bibiko |
317 |
NSInteger adjLocation = location + 2;
|
|
|
318 |
for(NSInteger i = 0; i < currentMaxFoldedIndex+1; i++) {
|
|
|
319 |
if(foldedRanges[i][2] > adjLocation && foldedRanges[i][0] < location) {
|
| 6233 |
bibiko |
320 |
index = i;
|
|
|
321 |
break;
|
|
|
322 |
}
|
|
|
323 |
}
|
|
|
324 |
}
|
| 6128 |
bibiko |
325 |
|
| 6233 |
bibiko |
326 |
if (index > -1) {
|
|
|
327 |
effectiveRange = NSMakeRange(foldedRanges[index][0]+1, foldedRanges[index][1]-2);
|
| 6238 |
bibiko |
328 |
// We adds NSAttachmentAttributeName if location is at beginning of folded range
|
| 6137 |
bibiko |
329 |
if (location == effectiveRange.location) { // beginning of a folded range
|
| 6233 |
bibiko |
330 |
|
| 6137 |
bibiko |
331 |
NSMutableDictionary *dict = [attributes mutableCopyWithZone:NULL];
|
|
|
332 |
[dict setObject:sharedAttachment forKey:NSAttachmentAttributeName];
|
|
|
333 |
attributes = [dict autorelease];
|
|
|
334 |
effectiveRange.length = 1;
|
| 6233 |
bibiko |
335 |
|
| 6137 |
bibiko |
336 |
} else {
|
|
|
337 |
++(effectiveRange.location); --(effectiveRange.length);
|
| 6128 |
bibiko |
338 |
}
|
| 6246 |
bibiko |
339 |
effectiveRange = NSIntersectionRange(effectiveRange, NSMakeRange(0, [_attributedString length]));
|
| 6137 |
bibiko |
340 |
if (range) *range = effectiveRange;
|
| 6128 |
bibiko |
341 |
}
|
|
|
342 |
|
|
|
343 |
return attributes;
|
| 6137 |
bibiko |
344 |
|
| 6128 |
bibiko |
345 |
}
|
|
|
346 |
|
| 7929 |
urbaneks |
347 |
- (void)edited:(NSTextStorageEditActions)mask range:(NSRange)oldRange changeInLength:(NSInteger)lengthChange
|
| 6233 |
bibiko |
348 |
{
|
|
|
349 |
|
|
|
350 |
if(foldedCounter && mask == NSTextStorageEditedCharacters) {
|
| 6238 |
bibiko |
351 |
// update foldedRanges array due to changes
|
|
|
352 |
NSInteger index = oldRange.location-1;
|
|
|
353 |
NSInteger maxOldRange = NSMaxRange(oldRange) + 1;
|
|
|
354 |
for(NSInteger i = 0; i < currentMaxFoldedIndex+1; i++) {
|
| 6233 |
bibiko |
355 |
if(index < foldedRanges[i][0]) {
|
| 6238 |
bibiko |
356 |
// if change covers the entire folded range -> delete it
|
|
|
357 |
if(foldedRanges[i][2] < maxOldRange && foldedRanges[i][0] > index) {
|
|
|
358 |
[self removeFoldedRangeWithIndex:i];
|
| 6233 |
bibiko |
359 |
continue;
|
|
|
360 |
}
|
| 6238 |
bibiko |
361 |
// otherwise correct folded start range and maxrange
|
| 6233 |
bibiko |
362 |
foldedRanges[i][0] += lengthChange;
|
| 6238 |
bibiko |
363 |
foldedRanges[i][2] += lengthChange;
|
|
|
364 |
// for safety delete it if new location is negative
|
|
|
365 |
if(foldedRanges[i][0] < 0) {
|
|
|
366 |
[self removeFoldedRangeWithIndex:i];
|
| 6233 |
bibiko |
367 |
}
|
|
|
368 |
}
|
|
|
369 |
}
|
|
|
370 |
}
|
|
|
371 |
|
|
|
372 |
[super edited:mask range:oldRange changeInLength:lengthChange];
|
|
|
373 |
}
|
|
|
374 |
|
| 6128 |
bibiko |
375 |
// NSMutableAttributedString primitives
|
|
|
376 |
- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str
|
|
|
377 |
{
|
| 7916 |
urbaneks |
378 |
[_attributedString replaceCharactersInRange:range withString:str];
|
|
|
379 |
[self edited:NSTextStorageEditedCharacters range:range changeInLength: [str length] - range.length];
|
| 6128 |
bibiko |
380 |
}
|
|
|
381 |
|
|
|
382 |
- (void)setAttributes:(NSDictionary *)attrs range:(NSRange)range
|
|
|
383 |
{
|
| 7916 |
urbaneks |
384 |
[_attributedString setAttributes:attrs range:range];
|
|
|
385 |
[self edited:NSTextStorageEditedAttributes range:range changeInLength:0];
|
| 6128 |
bibiko |
386 |
}
|
|
|
387 |
|
|
|
388 |
// Attribute Fixing Overrides
|
|
|
389 |
/*
|
|
|
390 |
- (void)fixAttributesInRange:(NSRange)range
|
|
|
391 |
{
|
|
|
392 |
[super fixAttributesInRange:range];
|
|
|
393 |
|
|
|
394 |
if(NSMaxRange(range) == 0) return;
|
|
|
395 |
|
|
|
396 |
// we want to avoid extending to the last paragraph separator
|
|
|
397 |
NSDictionary *attributeDict;
|
|
|
398 |
NSRange effectiveRange = { 0, 0 };
|
|
|
399 |
NSUInteger idx = range.location;
|
|
|
400 |
while (NSMaxRange(effectiveRange) < NSMaxRange(range)) {
|
|
|
401 |
attributeDict = [_attributedString attributesAtIndex:idx
|
|
|
402 |
longestEffectiveRange:&effectiveRange
|
|
|
403 |
inRange:range];
|
|
|
404 |
id value = [attributeDict objectForKey:foldingAttributeName];
|
|
|
405 |
if (value && effectiveRange.length) {
|
|
|
406 |
NSUInteger paragraphStart, paragraphEnd, contentsEnd;
|
|
|
407 |
[[self string] getParagraphStart:¶graphStart end:¶graphEnd contentsEnd:&contentsEnd forRange:range];
|
|
|
408 |
if ((NSMaxRange(range) == paragraphEnd) && (contentsEnd < paragraphEnd)) {
|
|
|
409 |
[self removeAttribute:foldingAttributeName range:NSMakeRange(contentsEnd, paragraphEnd - contentsEnd)];
|
|
|
410 |
}
|
|
|
411 |
}
|
|
|
412 |
idx = NSMaxRange(effectiveRange);
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
// 10.6 implementation
|
|
|
416 |
// [self enumerateAttribute:lineFoldingAttributeName inRange:range options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {
|
|
|
417 |
// if (value && (range.length > 1)) {
|
|
|
418 |
// NSUInteger paragraphStart, paragraphEnd, contentsEnd;
|
|
|
419 |
// [[self string] getParagraphStart:¶graphStart end:¶graphEnd contentsEnd:&contentsEnd forRange:range];
|
|
|
420 |
// if ((NSMaxRange(range) == paragraphEnd) && (contentsEnd < paragraphEnd)) {
|
|
|
421 |
// [self removeAttribute:lineFoldingAttributeName range:NSMakeRange(contentsEnd, paragraphEnd - contentsEnd)];
|
|
|
422 |
// }
|
|
|
423 |
// }
|
|
|
424 |
// }];
|
|
|
425 |
}
|
|
|
426 |
*/
|
|
|
427 |
|
|
|
428 |
@end
|