search: refactor appendUserTag to make logic more clear
ocd mostly
This commit is contained in:
@@ -41,18 +41,18 @@ struct UserSearch: View {
|
|||||||
appendUserTag(withTag: user_tag)
|
appendUserTag(withTag: user_tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func appendUserTag(withTag tagAttributedString: NSMutableAttributedString) {
|
private func appendUserTag(withTag tag: NSMutableAttributedString) {
|
||||||
guard let wordRange = focusWordAttributes.1 else {
|
guard let wordRange = focusWordAttributes.1 else { return }
|
||||||
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
|
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)
|
focusWordAttributes = (nil, nil)
|
||||||
newCursorIndex = wordRange.location + tagAttributedString.string.count
|
newCursorIndex = wordRange.location + tag.string.count
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|||||||
Reference in New Issue
Block a user