From deaf5f042a637b8d509bf900c93c4577bb495d29 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 17 Jul 2023 08:43:24 -0700 Subject: [PATCH] search: refactor appendUserTag to make logic more clear ocd mostly --- damus/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 index e05e335a..af8e7da1 100644 --- 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 {