damus

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

commit deaf5f042a637b8d509bf900c93c4577bb495d29
parent 4f56ff3dfb25eaacfac70e0a7bf946bfb11c6eae
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 17 Jul 2023 08:43:24 -0700

search: refactor appendUserTag to make logic more clear

ocd mostly

Diffstat:
Mdamus/Views/Posting/UserSearch.swift | 22+++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/damus/Views/Posting/UserSearch.swift b/damus/Views/Posting/UserSearch.swift @@ -41,18 +41,18 @@ struct UserSearch: View { appendUserTag(withTag: user_tag) } - private func appendUserTag(withTag tagAttributedString: NSMutableAttributedString) { - guard let wordRange = focusWordAttributes.1 else { - return - } - let mutableString = NSMutableAttributedString(attributedString: post) - mutableString.replaceCharacters(in: wordRange, with: tagAttributedString) - ///adjust cursor position appropriately: ('diff' used in TextViewWrapper / updateUIView after below update of 'post') - tagModel.diff = tagAttributedString.length - wordRange.length - - post = mutableString + 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) + + /// adjust cursor position appropriately: ('diff' used in TextViewWrapper / updateUIView after below update of 'post') + tagModel.diff = tag.length - wordRange.length + + post = new_post focusWordAttributes = (nil, nil) - newCursorIndex = wordRange.location + tagAttributedString.string.count + newCursorIndex = wordRange.location + tag.string.count } var body: some View {