damus

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

commit b26eedc633a8ae02e105d0493d8ecbe7a9ff304f
parent 793970beafb762ed74f99718f626a2ad5cd65a75
Author: Terry Yiu <git@tyiu.xyz>
Date:   Sun, 20 Jul 2025 01:25:58 -0400

Fix note content rendering to not remove whitespace before hashtag

Changelog-Fixed: Fixed note content rendering to not remove whitespace before hashtag

Closes: https://github.com/damus-io/damus/issues/3122
Fixes: f436291209e2 ("Fix note content rendering to not remove whitespace before hashtag")
Signed-off-by: Terry Yiu <git@tyiu.xyz>

Diffstat:
Mdamus/Models/NoteContent.swift | 15++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/damus/Models/NoteContent.swift b/damus/Models/NoteContent.swift @@ -76,6 +76,11 @@ func render_note_content(ev: NostrEvent, profiles: Profiles, keypair: Keypair) - return .separated(render_blocks(blocks: blocks, profiles: profiles, can_hide_last_previewable_refs: true)) } +// FIXME(tyiu): There are a lot of hacks to get this function to render the blocks correctly. +// However, the entire note content rendering logic just needs to be rewritten. +// Block previews should actually be rendered in the position of the note content where it was found. +// Currently, we put some previews at the bottom of the note, which is incorrect as they take things out of +// the author's intended context. func render_blocks(blocks bs: Blocks, profiles: Profiles, can_hide_last_previewable_refs: Bool = false) -> NoteArtifactsSeparated { var invoices: [Invoice] = [] var urls: [UrlType] = [] @@ -120,6 +125,7 @@ func render_blocks(blocks bs: Blocks, profiles: Profiles, can_hide_last_previewa // We should hide whitespace at the end sequence. hide_text_index = i } else if case .hashtag = block { + // SPECIAL CASE: // We should keep hashtags at the end sequence but hide all the other previewables around it. hide_text_index = i } else { @@ -171,7 +177,14 @@ func render_blocks(blocks bs: Blocks, profiles: Profiles, can_hide_last_previewa case .mention(let m): return str + mention_str(m, profiles: profiles) case .text(let txt): - return str + CompatibleText(stringLiteral: reduce_text_block(ind: ind, hide_text_index: hide_text_index, txt: txt)) + if case .hashtag = blocks[safe: ind+1] { + // SPECIAL CASE: + // Do not trim whitespaces from suffix if the following block is a hashtag. + // This is because of the code further up (see "SPECIAL CASE"). + return str + CompatibleText(stringLiteral: reduce_text_block(ind: ind, hide_text_index: -1, txt: txt)) + } else { + return str + CompatibleText(stringLiteral: reduce_text_block(ind: ind, hide_text_index: hide_text_index, txt: txt)) + } case .relay(let relay): return str + CompatibleText(stringLiteral: relay) case .hashtag(let htag):