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
This commit is contained in:
1 parent
60a0c21272
commit
fe82134a75
1 file changed
+5
-7
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user