mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Video avatar fixes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import Foundation
|
||||
import TextFormat
|
||||
import Postbox
|
||||
import AccountContext
|
||||
|
||||
func chatTextInputAddFormattingAttribute(_ state: ChatTextInputState, attribute: NSAttributedString.Key) -> ChatTextInputState {
|
||||
@@ -75,3 +76,33 @@ func chatTextInputAddLinkAttribute(_ state: ChatTextInputState, url: String) ->
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
func chatTextInputAddMentionAttribute(_ state: ChatTextInputState, peer: Peer) -> ChatTextInputState {
|
||||
let inputText = NSMutableAttributedString(attributedString: state.inputText)
|
||||
|
||||
let range = NSMakeRange(state.selectionRange.startIndex, state.selectionRange.endIndex - state.selectionRange.startIndex)
|
||||
|
||||
if let addressName = peer.addressName, !addressName.isEmpty {
|
||||
let replacementText = "@\(addressName) "
|
||||
|
||||
inputText.replaceCharacters(in: range, with: replacementText)
|
||||
|
||||
let selectionPosition = range.lowerBound + (replacementText as NSString).length
|
||||
|
||||
return ChatTextInputState(inputText: inputText, selectionRange: selectionPosition ..< selectionPosition)
|
||||
} else if !peer.compactDisplayTitle.isEmpty {
|
||||
let replacementText = NSMutableAttributedString()
|
||||
replacementText.append(NSAttributedString(string: peer.compactDisplayTitle, attributes: [ChatTextInputAttributes.textMention: ChatTextInputTextMentionAttribute(peerId: peer.id)]))
|
||||
replacementText.append(NSAttributedString(string: " "))
|
||||
|
||||
let updatedRange = NSRange(location: range.location , length: range.length)
|
||||
|
||||
inputText.replaceCharacters(in: updatedRange, with: replacementText)
|
||||
|
||||
let selectionPosition = updatedRange.lowerBound + replacementText.length
|
||||
|
||||
return ChatTextInputState(inputText: inputText, selectionRange: selectionPosition ..< selectionPosition)
|
||||
} else {
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user