diff --git a/ChangeLog b/ChangeLog index fa8fb2bb9..9e547a8d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-03-06 Richard Frith-Macdonald + + * Source/GSAttributedString.m: Applied fix for left-over attributes + at end of string. Patch supplied by Alexander Malmberg + . Reformatting to conform to GNUstep + standards, and optimisation by me. + 2002-03-04 Richard Frith-Macdonald * Tools/autogsdoc.m: Output gsdoc as UTF8 as we should. diff --git a/Source/GSAttributedString.m b/Source/GSAttributedString.m index 6c6ec9fc5..734b244d1 100644 --- a/Source/GSAttributedString.m +++ b/Source/GSAttributedString.m @@ -57,6 +57,8 @@ #define SANITY_CHECKS 0 +static NSDictionary *blank; + @interface GSAttributedString : NSAttributedString { NSString *_textChars; @@ -268,6 +270,7 @@ static void _setup() if (infCls == 0) { NSMutableArray *a; + NSDictionary *d; GSIMapInitWithZoneAndCapacity(&attrMap, NSDefaultMallocZone(), 32); @@ -289,6 +292,9 @@ static void _setup() oatImp = [a methodForSelector: oatSel]; remImp = (void (*)())[a methodForSelector: remSel]; RELEASE(a); + d = [NSDictionary new]; + blank = cacheAttributes(d); + RELEASE(d); } } @@ -311,7 +317,7 @@ _setAttributesFrom( if (aRange.length == 0) { - attr = [NSDictionary dictionary]; + attr = blank; } else { @@ -469,7 +475,7 @@ _attributesAtIndexEffectiveRange( if (attributes == nil) { - attributes = [NSDictionary dictionary]; + attributes = blank; } attributes = cacheAttributes(attributes); info = NEWINFO(z, attributes, 0); @@ -533,7 +539,7 @@ _attributesAtIndexEffectiveRange( { info = OBJECTAT(i); NSAssert(info->loc > l, NSInternalInconsistencyException); - NSAssert(info->loc <= len, NSInternalInconsistencyException); + NSAssert(info->loc < len, NSInternalInconsistencyException); l = info->loc; } } @@ -565,7 +571,7 @@ _attributesAtIndexEffectiveRange( if (attributes == nil) { - attributes = [NSDictionary dictionary]; + attributes = blank; } attributes = cacheAttributes(attributes); info = NEWINFO(z, attributes, 0); @@ -625,7 +631,7 @@ SANITY(); } if (attributes == nil) { - attributes = [NSDictionary dictionary]; + attributes = blank; } attributes = cacheAttributes(attributes); SANITY(); @@ -783,6 +789,8 @@ SANITY(); attrs = _attributesAtIndexEffectiveRange(start, &effectiveRange, tmpLength, _infoArray, &arrayIndex); + moveLocations = [aString length] - range.length; + arrayIndex++; if (NSMaxRange(effectiveRange) < NSMaxRange(range)) { @@ -811,10 +819,32 @@ SANITY(); } } } - info->loc = NSMaxRange(range); + if (NSMaxRange(range) < [_textChars length]) + { + info->loc = NSMaxRange(range); + } + else + { + if (arrayIndex != 0) + { + REMOVEAT(arrayIndex); + arraySize--; + } + else + { + NSDictionary *d = blank; + + unCacheAttributes(info->attrs); + DESTROY(info->attrs); + d = cacheAttributes(d); + info->attrs = d; + /* set location so it will be correct after being modified + below */ + info->loc = NSMaxRange(range); + } + } } - moveLocations = [aString length] - range.length; /* * If we are replacing a range with a zero length string and the * range we are using matches the range replaced, then we must @@ -827,12 +857,26 @@ SANITY(); arrayIndex++; if (effectiveRange.location == range.location - && effectiveRange.length == range.length) - { - arrayIndex--; - REMOVEAT(arrayIndex); - arraySize--; - } + && effectiveRange.length == range.length) + { + arrayIndex--; + if (arrayIndex!=0) + { + REMOVEAT(arrayIndex); + arraySize--; + } + else + { + NSDictionary *d = blank; + + info = OBJECTAT(0); + unCacheAttributes(info->attrs); + DESTROY(info->attrs); + d = cacheAttributes(d); + info->attrs = d; + info->loc = NSMaxRange(range); + } + } } /*