Skip to content

Commit dd061b8

Browse files
authored
Merge pull request #1287 from ximmyxiao/develop
fix appendString defined duplicated in iOS18
2 parents 35a111b + 959d696 commit dd061b8

5 files changed

+37
-3
lines changed

Core/Source/DTHTMLAttributedStringBuilder.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ - (void)parser:(DTHTMLParser *)parser didEndElement:(NSString *)elementName
876876
[strongSelf->_tmpString deleteCharactersInRange:NSMakeRange([strongSelf->_tmpString length]-1, 1)];
877877
}
878878

879-
[strongSelf->_tmpString appendString:@"\n"];
879+
[strongSelf->_tmpString dt_appendString:@"\n"];
880880
}
881881
}
882882

Core/Source/DTHTMLElement.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ - (NSAttributedString *)attributedString
490490
}
491491

492492
// paragraph break
493-
[tmpString appendString:@"\n"];
493+
[tmpString dt_appendString:@"\n"];
494494
}
495495
}
496496

Core/Source/DTTextAttachmentHTMLElement.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ - (NSAttributedString *)attributedString
6969
// block-level elements get space trimmed and a newline
7070
if (self.displayStyle != DTHTMLElementDisplayStyleInline)
7171
{
72-
[tmpString appendString:@"\n"];
72+
[tmpString dt_appendString:@"\n"];
7373
}
7474

7575
return tmpString;

Core/Source/NSMutableAttributedString+HTML.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
If the last character of the receiver contains a placeholder for a <DTTextAttachment> it is removed from the appended string. Also fields (e.g. list prefixes) are not extended
2424
@param string The string to be appended to this string. */
2525
- (void)appendString:(NSString *)string;
26+
- (void)dt_appendString:(NSString *)string;// added this prefix version of appendString ,because the appendString method defined duplication in iOS18 ,appendString will also defined in ScreenReaderCore.framework
2627

2728
/**
2829
Appends a string with a given paragraph style and font to this string.

Core/Source/NSMutableAttributedString+HTML.m

+33
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,39 @@
1919

2020
@implementation NSMutableAttributedString (HTML)
2121

22+
// the same as appendString just to avoid method repeat problem in iOS18 . If everything works well for somethime , the original appendString can be removed
23+
- (void)dt_appendString:(NSString *)string
24+
{
25+
NSParameterAssert(string);
26+
27+
NSUInteger length = [self length];
28+
NSAttributedString *appendString = nil;
29+
30+
if (length)
31+
{
32+
// get attributes at end of self
33+
NSMutableDictionary *attributes = [[self attributesAtIndex:length-1 effectiveRange:NULL] mutableCopy];
34+
35+
// we need to remove the image placeholder (if any) to prevent duplication
36+
[attributes removeObjectForKey:NSAttachmentAttributeName];
37+
[attributes removeObjectForKey:(id)kCTRunDelegateAttributeName];
38+
39+
// we also remove field attribute, because appending plain strings should never extend an field
40+
[attributes removeObjectForKey:DTFieldAttribute];
41+
42+
// create a temp attributed string from the appended part
43+
appendString = [[NSAttributedString alloc] initWithString:string attributes:attributes];
44+
}
45+
else
46+
{
47+
// no attributes to extend
48+
appendString = [[NSAttributedString alloc] initWithString:string];
49+
}
50+
51+
[self appendAttributedString:appendString];
52+
}
53+
54+
2255

2356
// appends a plain string extending the attributes at this position
2457
- (void)appendString:(NSString *)string

0 commit comments

Comments
 (0)