Attributed range fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8586 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2001-01-13 20:33:58 +00:00
parent db4d0ae312
commit fc7d151cf6
3 changed files with 25 additions and 10 deletions

View file

@ -4,6 +4,10 @@
Added destination data cpacity information to context so that
correct positioning can be maintained over a sequence of calls
using a chunked http context.
* Source/GSAttributedString.m: Fixed bug initialising from an
empty attributed string, and fixed bug replacing characters in
range, when an attribute range location is the same s the location
of the replaced characters.
2001-01-12 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -303,11 +303,15 @@ _setAttributesFrom(
*/
[_infoArray removeAllObjects];
if (aRange.length <= 0)
return;
attr = [attributedString attributesAtIndex: aRange.location
effectiveRange: &range];
if (aRange.length == 0)
{
attr = [NSDictionary dictionary];
}
else
{
attr = [attributedString attributesAtIndex: aRange.location
effectiveRange: &range];
}
attr = cacheAttributes(attr);
info = NEWINFO(z, attr, 0);
ADDOBJECT(info);
@ -447,9 +451,11 @@ _attributesAtIndexEffectiveRange(
if (aString != nil && [aString isKindOfClass: [NSAttributedString class]])
{
NSAttributedString *as = (NSAttributedString*)aString;
unsigned len;
aString = [as string];
_setAttributesFrom(as, NSMakeRange(0, [aString length]), _infoArray);
len = [aString length];
_setAttributesFrom(as, NSMakeRange(0, len), _infoArray);
}
else
{
@ -546,7 +552,6 @@ _attributesAtIndexEffectiveRange(
aString = [as string];
_setAttributesFrom(as, NSMakeRange(0, [aString length]), _infoArray);
SANITY();
}
else
{
@ -565,6 +570,7 @@ SANITY();
_textChars = [[NSMutableString allocWithZone: z] init];
else
_textChars = [aString mutableCopyWithZone: z];
SANITY();
return self;
}
@ -800,6 +806,7 @@ SANITY();
moveLocations = [aString length] - range.length;
if (effectiveRange.location == range.location
&& effectiveRange.length == range.length
&& (moveLocations + range.length) == 0)
{
/*
@ -812,7 +819,6 @@ SANITY();
arraySize--;
}
SANITY();
/*
* Now adjust the positions of the ranges following the one we are using.
*/
@ -822,7 +828,6 @@ SANITY();
info->loc += moveLocations;
arrayIndex++;
}
SANITY();
[_textChars replaceCharactersInRange: range withString: aString];
finish:
SANITY();

View file

@ -74,7 +74,13 @@ void testAttributedString(void)
NSAttributedString *attrString;
NSMutableAttributedString *muAttrString,*muAttrString2;
NSMutableDictionary *attributes,*colorAttributes,*twoAttributes;
NSMutableAttributedString *text;
text = [[NSMutableAttributedString alloc] initWithString: @"this is a bug"];
[text addAttribute: @"foo" value: @"bar" range: NSMakeRange(0,4)];
[text deleteCharactersInRange: NSMakeRange(0,1)];
[text attribute: @"foo" atIndex: 0 effectiveRange: 0];
attributes = [[[NSMutableDictionary alloc] init] autorelease];
[attributes setObject:@"Helvetica 12-point"
forKey:NSFontAttributeName];