damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 7bf18336d023f7ad1ea3043f4a0134d0af5c9c3c
parent b131c74ee367a8c12fda70cce555eeeb22aeaf60
Author: William Casarin <jb55@jb55.com>
Date:   Wed,  5 Apr 2023 13:12:56 -0700

Fix extraneous padding on some image posts

Changelog-Fixed: Fix extraneous padding on some image posts

Diffstat:
Mdamus/Views/NoteContentView.swift | 12+++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift @@ -260,7 +260,10 @@ func render_blocks(blocks: [Block], profiles: Profiles, privkey: String?) -> Not .filter({ $0.is_note_mention }) .count == 1 + var ind: Int = -1 let txt: AttributedString = blocks.reduce("") { str, block in + ind = ind + 1 + switch block { case .mention(let m): if m.type == .event && one_note_ref { @@ -268,7 +271,14 @@ func render_blocks(blocks: [Block], profiles: Profiles, privkey: String?) -> Not } return str + mention_str(m, profiles: profiles) case .text(let txt): - return str + AttributedString(stringLiteral: txt) + var trimmed = txt + if let prev = blocks[safe: ind-1], case .url(let u) = prev, is_image_url(u) { + trimmed = " " + trim_prefix(trimmed) + } + if let next = blocks[safe: ind+1], case .url(let u) = next, is_image_url(u) { + trimmed = trim_suffix(trimmed) + } + return str + AttributedString(stringLiteral: trimmed) case .hashtag(let htag): return str + hashtag_str(htag) case .invoice(let invoice):