Composer: Trim attachement characters

This commit is contained in:
Thomas Ricouard 2023-01-19 11:58:58 +01:00
parent 47004d00c1
commit 09c09d5ea9
1 changed files with 7 additions and 7 deletions

View File

@ -245,18 +245,18 @@ public class StatusEditorViewModel: ObservableObject {
range: NSRange(location: range.location, length: range.length))
}
var attachmentsToRemove: [NSRange] = []
statusText.enumerateAttribute(.attachment, in: range) { attachment, _, _ in
var mediaAdded: Bool = false
statusText.enumerateAttribute(.attachment, in: range) { attachment, range, _ in
if let attachment = attachment as? NSTextAttachment, let image = attachment.image {
attachmentsToRemove.append(range)
mediasImages.append(.init(image: image, mediaAttachment: nil, error: nil))
statusText.removeAttribute(.attachment, range: range)
statusText.mutableString.deleteCharacters(in: range)
mediaAdded = true
}
}
if !attachmentsToRemove.isEmpty {
if mediaAdded {
processMediasToUpload()
for range in attachmentsToRemove {
statusText.removeAttribute(.attachment, range: range)
}
}
} catch {}
}