replaceSelection(_:with:)
Replace the selection with new attributed content.
Declaration
mutating func replaceSelection(_ selection: inout AttributedTextSelection, with newContent: some AttributedStringProtocol)Discussion
In the case the selection is an insertion point, the newContent gets inserted at the caret location and the caret is moved to after the new content.
In the case where the selection spans one or multiple characters, those characters are removed and the new content is inserted at location of the first selected character.