From fe82134a75b8b868d9d43a54c1ac29131bba4871 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 17 Jul 2023 10:22:10 -0700 Subject: [PATCH] posting: switch to new tested composition logic This switches to the new post composition logic in the post view. It adds a space at the begging of a mention if it is needed. We still need to make the state in these view more pure so we can test more of the posting logic like cursor positions after posting, etc. Changelog-Added: Add space when tagging users in posts if needed Changelog-Fixed: Fix issue where typing cc@bob would produce brokenb ccnostr:bob mention --- damus/Views/Posting/UserSearch.swift | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/damus/Views/Posting/UserSearch.swift b/damus/Views/Posting/UserSearch.swift index e658841e..0f3a7a66 100644 --- a/damus/Views/Posting/UserSearch.swift +++ b/damus/Views/Posting/UserSearch.swift @@ -36,7 +36,6 @@ struct UserSearch: View { } let user_tag = user_tag_attr_string(profile: user.profile, pubkey: pk) - user_tag.append(.init(string: " ")) appendUserTag(withTag: user_tag) } @@ -44,15 +43,14 @@ struct UserSearch: View { private func appendUserTag(withTag tag: NSMutableAttributedString) { guard let wordRange = focusWordAttributes.1 else { return } - let new_post = NSMutableAttributedString(attributedString: post) - new_post.replaceCharacters(in: wordRange, with: tag) + let appended = append_user_tag(tag: tag, post: post, word_range: wordRange) + self.post = appended.post - /// adjust cursor position appropriately: ('diff' used in TextViewWrapper / updateUIView after below update of 'post') - tagModel.diff = tag.length - wordRange.length + // adjust cursor position appropriately: ('diff' used in TextViewWrapper / updateUIView after below update of 'post') + tagModel.diff = appended.tag.length - wordRange.length - post = new_post focusWordAttributes = (nil, nil) - newCursorIndex = wordRange.location + tag.string.count + newCursorIndex = wordRange.location + appended.tag.string.count } var body: some View {