diff --git a/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/View/MessageComposerTextField.swift b/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/View/MessageComposerTextField.swift index d2bc028132..9f78fdaddf 100644 --- a/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/View/MessageComposerTextField.swift +++ b/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/View/MessageComposerTextField.swift @@ -105,6 +105,9 @@ private struct UITextViewWrapper: UIViewRepresentable { .foregroundColor: UIColor(.compound.textPrimary)] if textView.attributedText != text { + // Remember the selection if only the attributes have changed. + let selection = textView.attributedText.string == text.string ? textView.selectedTextRange : nil + textView.attributedText = text // Re-apply the default font when setting text for e.g. edits. @@ -120,6 +123,10 @@ private struct UITextViewWrapper: UIViewRepresentable { textView.keyboardType = .default textView.reloadInputViews() } + } else if let selection { + // Fixes a bug where pressing Return in the middle of two paragraphs + // moves the caret back to the bottom of the composer. + textView.selectedTextRange = selection } } }