From bb31177910c5ed88f8937439a116031289641799 Mon Sep 17 00:00:00 2001 From: Josh Brown Date: Tue, 13 Feb 2024 16:46:54 -0500 Subject: [PATCH 1/2] #535: Append a space after inserting a mention --- Nos/Models/EditableNoteText.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Nos/Models/EditableNoteText.swift b/Nos/Models/EditableNoteText.swift index fd4ba2ac6..c32ea8e5b 100644 --- a/Nos/Models/EditableNoteText.swift +++ b/Nos/Models/EditableNoteText.swift @@ -84,37 +84,42 @@ struct EditableNoteText: Equatable { return } - let mention = AttributedString( + var mention = AttributedString( "@\(author.safeName)", attributes: defaultAttributes.merging( AttributeContainer([NSAttributedString.Key.link: url.absoluteString]) ) ) - + mention.append(AttributedString(stringLiteral: " ")) + attributedString.replaceSubrange((attributedString.index(beforeCharacter: index))..) { - let mention = AttributedString( + var mention = AttributedString( "@\(npub.prefix(10).appending("..."))", attributes: defaultAttributes.merging( AttributeContainer([NSAttributedString.Key.link: "nostr:\(npub)"]) ) ) + mention.append(AttributedString(stringLiteral: " ")) + attributedString.replaceSubrange(range, with: mention) } /// Inserts the mention of an author as a link at the given index of the string. The `index` should be the index /// after a `@` character, which this function will replace. mutating func insertMention(note: String, at range: Range) { - let mention = AttributedString( + var mention = AttributedString( "@\(note.prefix(10).appending("..."))", attributes: defaultAttributes.merging( AttributeContainer([NSAttributedString.Key.link: "nostr:\(note)"]) ) ) + mention.append(AttributedString(stringLiteral: " ")) + attributedString.replaceSubrange(range, with: mention) } From 4a981ccaa896b6d9d468dd10131362865579d2b7 Mon Sep 17 00:00:00 2001 From: Josh Brown Date: Tue, 13 Feb 2024 16:56:11 -0500 Subject: [PATCH 2/2] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab186b0bc..408a1b135 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- While composing a note, a space is now automatically inserted after any mention of a user or note to ensure it’s formatted correctly. - Fixed an issue where tapping the Feed tab did not scroll to the top of the Feed. - Fixed an issue where tapping the Profile tab did not scroll to the top of the Profile. - Search now starts automatically after entering three characters instead of one.