Fix wrong separated components in messageInputBar#577
Fix wrong separated components in messageInputBar#577SD10 merged 2 commits intoMessageKit:masterfrom
Conversation
SD10
left a comment
There was a problem hiding this comment.
I'm good with this but I got lost on the second half of the logic. It may be good to wait and have @nathantannar4 review this as he is the original author.
| } | ||
| } | ||
|
|
||
| var curLocation = 0 |
There was a problem hiding this comment.
@zhongwuzw Can you help me understand the code from here? I just want to understand before we merge if Nathan doesn't have time to look at this one
There was a problem hiding this comment.
@SD10 , First we should enumerate all .attachment, get its image and range, then we can split text and image based on the range.
| } | ||
| } | ||
|
|
||
| var curLocation = 0 |
There was a problem hiding this comment.
@SD10 , First we should enumerate all .attachment, get its image and range, then we can split text and image based on the range.
| } | ||
|
|
||
| var curLocation = 0 | ||
| if attachments.count == 0 { |
| let (range, image) = attachment | ||
| if curLocation < range.location { | ||
| let textRange = NSMakeRange(curLocation, range.location) | ||
| let text = attributedText.attributedSubstring(from: textRange).string.trimmingCharacters(in: .whitespacesAndNewlines) |
There was a problem hiding this comment.
Add text and image to components
| curLocation = range.location + range.length | ||
| components.append(image) | ||
| } | ||
| if curLocation < length - 1 { |
There was a problem hiding this comment.
After last image, maybe still has text, so we should append it to components.
There was a problem hiding this comment.
😄 It's because we add a new line after image, so we decrease 1 to prevent unnecessary calculation.
SD10
left a comment
There was a problem hiding this comment.
@zhongwuzw Thanks for walking me through this 👍
Fix #569