mention: fix broken mentions when there is text is directly after
If a user adds text right after a mention without a space, a space gets added so the mention can be parsed correctly after posting. Closes: https://github.com/damus-io/damus/issues/1872 Changelog-Fixed: Fix broken mentions when there is text is directly after Lightning-url: LNURL1DP68GURN8GHJ7EM9W3SKCCNE9E3K7MF0D3H82UNVWQHKWUN9V4HXGCTHDC6RZVGR8SW3G Signed-off-by: kernelkind <kernelkind@gmail.com> Reviewed-by: William Casarin <jb55@jb55.com> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
aa1f75ad58
commit
af75eed83a
@@ -617,6 +617,13 @@ func load_draft_for_post(drafts: Drafts, action: PostAction) -> DraftArtifacts?
|
||||
func build_post(state: DamusState, post: NSMutableAttributedString, action: PostAction, uploadedMedias: [UploadedMedia], references: [RefId]) -> NostrPost {
|
||||
post.enumerateAttributes(in: NSRange(location: 0, length: post.length), options: []) { attributes, range, stop in
|
||||
if let link = attributes[.link] as? String {
|
||||
let nextCharIndex = range.upperBound
|
||||
if nextCharIndex < post.length,
|
||||
let nextChar = post.attributedSubstring(from: NSRange(location: nextCharIndex, length: 1)).string.first,
|
||||
!nextChar.isWhitespace {
|
||||
post.insert(NSAttributedString(string: " "), at: nextCharIndex)
|
||||
}
|
||||
|
||||
let normalized_link: String
|
||||
if link.hasPrefix("damus:nostr:") {
|
||||
// Replace damus:nostr: URI prefix with nostr: since the former is for internal navigation and not meant to be posted.
|
||||
|
||||
Reference in New Issue
Block a user