Fix cursor jumping when pressing return

Changelog-Fixed: Fix cursor jumping when pressing return
Closes: #775
This commit is contained in:
gladius
2023-03-06 03:31:38 -05:00
committed by William Casarin
parent 59e7a42b5f
commit e4e477a2ac
3 changed files with 18 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ struct UserSearch: View {
@Binding var postTextViewCanScroll: Bool
@Binding var post: NSMutableAttributedString
@EnvironmentObject var tagModel: TagModel
var users: [SearchedUser] {
guard let contacts = damus_state.contacts.event else {
@@ -48,6 +49,9 @@ struct UserSearch: View {
}
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
focusWordAttributes = (nil, nil)
newCursorIndex = wordRange.location + tagAttributedString.string.count