Author: ericwa
Date: Thu Mar 20 06:05:22 2014
New Revision: 10596
URL: http://svn.gna.org/viewcvs/etoile?rev=10596&view=rev
Log:
COAttributedStringWrapper: eliminate one source of empty chunks, which were
cluttering and slowing down the object graph after editing for a while
Modified:
trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringWrapper.m
trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringWrapper.m
Modified:
trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringWrapper.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringWrapper.m?rev=10596&r1=10595&r2=10596&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringWrapper.m
(original)
+++ trunk/Etoile/Frameworks/CoreObject/Extras/Model/COAttributedStringWrapper.m
Thu Mar 20 06:05:22 2014
@@ -452,6 +452,11 @@
NSString *newText = [chunk.text stringByReplacingCharactersInRange:
NSMakeRange(indexInChunk, lengthInChunkToReplace) withString: aString];
chunk.text = newText;
+ if ([newText length] == 0)
+ {
+ [[_backing mutableArrayValueForKey: @"chunks"]
removeObjectAtIndex: chunkIndex--];
+ }
+
NSUInteger remainingLengthToDelete = aRange.length -
lengthInChunkToReplace;
while (remainingLengthToDelete > 0)
@@ -463,6 +468,11 @@
lengthInChunkToReplace = MIN([[chunk text] length],
remainingLengthToDelete);
chunk.text = [chunk.text stringByReplacingCharactersInRange:
NSMakeRange(0, lengthInChunkToReplace) withString: @""];
remainingLengthToDelete -= lengthInChunkToReplace;
+
+ if ([chunk.text length] == 0)
+ {
+ [[_backing mutableArrayValueForKey: @"chunks"]
removeObjectAtIndex: chunkIndex--];
+ }
}
// TODO: Add tests that check for this
Modified:
trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringWrapper.m
URL:
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringWrapper.m?rev=10596&r1=10595&r2=10596&view=diff
==============================================================================
---
trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringWrapper.m
(original)
+++
trunk/Etoile/Frameworks/CoreObject/Tests/Extras/Model/TestAttributedStringWrapper.m
Thu Mar 20 06:05:22 2014
@@ -433,6 +433,31 @@
} modifiesRange: NSMakeRange(1, 1) mask: NSTextStorageEditedCharacters
| NSTextStorageEditedAttributes delta: -1 newString: @"ad"];
}
+- (void) testReplacingSingleChunkWithEmptyStringDeletesChunk
+{
+ [self appendHTMLString: @"a<B>b</B><I>c</I>" toAttributedString:
attributedString];
+
+ [as replaceCharactersInRange: NSMakeRange(1, 1) withString: @""];
+
+ UKObjectsEqual(@"ac", [as string]);
+ UKIntsEqual(2, [attributedString.chunks count]);
+ UKObjectsEqual(@"a", [attributedString.chunks[0] text]);
+ UKObjectsEqual(@"c", [attributedString.chunks[1] text]);
+}
+
+- (void) testReplacingMultipleChunksWithEmptyStringDeletesChunk
+{
+ [self appendHTMLString: @"a<B>b</B><I>c</I><U>dd</U>"
toAttributedString: attributedString];
+
+ // Delete chunks 'b' and 'c', and the first character of 'dd'
+ [as replaceCharactersInRange: NSMakeRange(1, 3) withString: @""];
+
+ UKObjectsEqual(@"ad", [as string]);
+ UKIntsEqual(2, [attributedString.chunks count]);
+ UKObjectsEqual(@"a", [attributedString.chunks[0] text]);
+ UKObjectsEqual(@"d", [attributedString.chunks[1] text]);
+}
+
@end
/**
_______________________________________________
Etoile-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-cvs