mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Quote improvements
This commit is contained in:
@@ -1212,13 +1212,23 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate, Ch
|
||||
|
||||
self.interfaceInteraction?.updateTextInputStateAndMode { current, inputMode in
|
||||
let result = NSMutableAttributedString(attributedString: current.inputText)
|
||||
var selectionRange = current.selectionRange
|
||||
|
||||
if let _ = result.attribute(ChatTextInputAttributes.block, at: range.lowerBound, effectiveRange: nil) as? ChatTextInputTextQuoteAttribute {
|
||||
let blockString = result.attributedSubstring(from: range)
|
||||
let blockString = NSMutableAttributedString(attributedString: result.attributedSubstring(from: range))
|
||||
blockString.removeAttribute(ChatTextInputAttributes.block, range: NSRange(location: 0, length: blockString.length))
|
||||
|
||||
result.replaceCharacters(in: range, with: "")
|
||||
result.insert(NSAttributedString(string: " ", attributes: [
|
||||
ChatTextInputAttributes.collapsedBlock: blockString
|
||||
]), at: range.lowerBound)
|
||||
|
||||
if selectionRange.lowerBound >= range.lowerBound && selectionRange.upperBound < range.upperBound {
|
||||
selectionRange = range.lowerBound ..< range.lowerBound
|
||||
} else if selectionRange.lowerBound >= range.upperBound {
|
||||
let deltaLength = 1 - range.length
|
||||
selectionRange = (selectionRange.lowerBound + deltaLength) ..< (selectionRange.lowerBound + deltaLength)
|
||||
}
|
||||
} else if let current = result.attribute(ChatTextInputAttributes.collapsedBlock, at: range.lowerBound, effectiveRange: nil) as? NSAttributedString {
|
||||
result.replaceCharacters(in: range, with: "")
|
||||
|
||||
@@ -1226,13 +1236,24 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate, Ch
|
||||
updatedBlockString.addAttribute(ChatTextInputAttributes.block, value: ChatTextInputTextQuoteAttribute(kind: .quote, isCollapsed: false), range: NSRange(location: 0, length: updatedBlockString.length))
|
||||
|
||||
result.insert(updatedBlockString, at: range.lowerBound)
|
||||
|
||||
if selectionRange.lowerBound >= range.upperBound {
|
||||
let deltaLength = updatedBlockString.length - 1
|
||||
selectionRange = (selectionRange.lowerBound + deltaLength) ..< (selectionRange.lowerBound + deltaLength)
|
||||
}
|
||||
}
|
||||
|
||||
let stateResult = stateAttributedStringForText(result)
|
||||
if selectionRange.lowerBound < 0 {
|
||||
selectionRange = 0 ..< selectionRange.upperBound
|
||||
}
|
||||
if selectionRange.upperBound > stateResult.length {
|
||||
selectionRange = selectionRange.lowerBound ..< stateResult.length
|
||||
}
|
||||
|
||||
return (ChatTextInputState(
|
||||
inputText: stateResult,
|
||||
selectionRange: current.selectionRange
|
||||
selectionRange: selectionRange
|
||||
), inputMode)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user