Composer: Trim attachement characters

This commit is contained in:
Thomas Ricouard 2023-01-19 11:58:58 +01:00
parent 47004d00c1
commit 09c09d5ea9

View file

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