Repository navigation
Fix wrong separated components in messageInputBar #577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -303,26 +303,50 @@ open class InputTextView: UITextView { | |
| private func parseForComponents() -> [Any] { | ||
|
|
||
| var components = [Any]() | ||
| let range = NSRange(location: 0, length: attributedText.length) | ||
| attributedText.enumerateAttributes(in: range, options: []) { (object, range, _) in | ||
|
|
||
| if object.keys.contains(.attachment) { | ||
| if let attachment = object[.attachment] as? NSTextAttachment { | ||
| if let image = attachment.image { | ||
| components.append(image) | ||
| } else if let image = attachment.image(forBounds: attachment.bounds, | ||
| textContainer: nil, | ||
| characterIndex: range.location) { | ||
| components.append(image) | ||
| var attachments = [(NSRange, UIImage)]() | ||
| let length = attributedText.length | ||
| let range = NSRange(location: 0, length: length) | ||
| attributedText.enumerateAttribute(.attachment, in: range) { (object, range, _) in | ||
| if let attachment = object as? NSTextAttachment { | ||
| if let image = attachment.image { | ||
| attachments.append((range, image)) | ||
| } else if let image = attachment.image(forBounds: attachment.bounds, | ||
| textContainer: nil, | ||
| characterIndex: range.location) { | ||
| attachments.append((range,image)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| var curLocation = 0 | ||
| if attachments.count == 0 { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SD10 If no images, just text. |
||
| let text = attributedText.string.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| if !text.isEmpty { | ||
| components.append(text) | ||
| } | ||
| } | ||
| else { | ||
| attachments.forEach { (attachment) in | ||
| let (range, image) = attachment | ||
| if curLocation < range.location { | ||
| let textRange = NSMakeRange(curLocation, range.location) | ||
| let text = attributedText.attributedSubstring(from: textRange).string.trimmingCharacters(in: .whitespacesAndNewlines) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add text and image to |
||
| if !text.isEmpty { | ||
| components.append(text) | ||
| } | ||
| } | ||
| } else { | ||
| let stringValue = attributedText.attributedSubstring(from: range).string.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| if !stringValue.isEmpty { | ||
| components.append(stringValue) | ||
|
|
||
| curLocation = range.location + range.length | ||
| components.append(image) | ||
| } | ||
| if curLocation < length - 1 { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After last
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😄 It's because we add a new line after image, so we decrease 1 to prevent unnecessary calculation. |
||
| let text = attributedText.attributedSubstring(from: NSMakeRange(curLocation, length - curLocation)).string.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| if !text.isEmpty { | ||
| components.append(text) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return components | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SD10 , First we should enumerate all
.attachment, get its image and range, then we can split text and image based on the range.