mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Blockquote experiments
This commit is contained in:
@@ -249,9 +249,11 @@ public final class ChatTextInputTextQuoteAttribute: NSObject {
|
||||
}
|
||||
|
||||
public let kind: Kind
|
||||
public let isCollapsed: Bool
|
||||
|
||||
public init(kind: Kind) {
|
||||
public init(kind: Kind, isCollapsed: Bool) {
|
||||
self.kind = kind
|
||||
self.isCollapsed = isCollapsed
|
||||
|
||||
super.init()
|
||||
}
|
||||
@@ -264,6 +266,9 @@ public final class ChatTextInputTextQuoteAttribute: NSObject {
|
||||
if self.kind != other.kind {
|
||||
return false
|
||||
}
|
||||
if self.isCollapsed != other.isCollapsed {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -646,7 +651,7 @@ private func refreshBlockQuotes(text: NSString, initialAttributedText: NSAttribu
|
||||
if !quoteRangesEqual(quoteRanges, initialQuoteRanges) {
|
||||
attributedText.removeAttribute(ChatTextInputAttributes.block, range: fullRange)
|
||||
for (range, attribute) in quoteRanges {
|
||||
attributedText.addAttribute(ChatTextInputAttributes.block, value: ChatTextInputTextQuoteAttribute(kind: attribute.kind), range: range)
|
||||
attributedText.addAttribute(ChatTextInputAttributes.block, value: ChatTextInputTextQuoteAttribute(kind: attribute.kind, isCollapsed: attribute.isCollapsed), range: range)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1067,7 +1072,7 @@ public func convertMarkdownToAttributes(_ text: NSAttributedString) -> NSAttribu
|
||||
substring = substring.substring(with: NSRange(location: 0, length: substring.length - 1)) as NSString
|
||||
}
|
||||
|
||||
result.append(NSAttributedString(string: substring as String, attributes: [ChatTextInputAttributes.block: ChatTextInputTextQuoteAttribute(kind: .code(language: language))]))
|
||||
result.append(NSAttributedString(string: substring as String, attributes: [ChatTextInputAttributes.block: ChatTextInputTextQuoteAttribute(kind: .code(language: language), isCollapsed: false)]))
|
||||
offsetRanges.append((NSMakeRange(matchIndex + match.range(at: 1).length, text.count), 6))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public func generateChatInputTextEntities(_ text: NSAttributedString, maxAnimate
|
||||
} else if key == ChatTextInputAttributes.block, let value = value as? ChatTextInputTextQuoteAttribute {
|
||||
switch value.kind {
|
||||
case .quote:
|
||||
entities.append(MessageTextEntity(range: range.lowerBound ..< range.upperBound, type: .BlockQuote(isCollapsed: false)))
|
||||
entities.append(MessageTextEntity(range: range.lowerBound ..< range.upperBound, type: .BlockQuote(isCollapsed: value.isCollapsed)))
|
||||
case let .code(language):
|
||||
entities.append(MessageTextEntity(range: range.lowerBound ..< range.upperBound, type: .Pre(language: language)))
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ public func chatInputStateStringWithAppliedEntities(_ text: String, entities: [M
|
||||
case let .CustomEmoji(_, fileId):
|
||||
string.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: fileId, file: nil), range: range)
|
||||
case let .Pre(language):
|
||||
string.addAttribute(ChatTextInputAttributes.block, value: ChatTextInputTextQuoteAttribute(kind: .code(language: language)), range: range)
|
||||
case .BlockQuote:
|
||||
string.addAttribute(ChatTextInputAttributes.block, value: ChatTextInputTextQuoteAttribute(kind: .quote), range: range)
|
||||
string.addAttribute(ChatTextInputAttributes.block, value: ChatTextInputTextQuoteAttribute(kind: .code(language: language), isCollapsed: false), range: range)
|
||||
case let .BlockQuote(isCollapsed):
|
||||
string.addAttribute(ChatTextInputAttributes.block, value: ChatTextInputTextQuoteAttribute(kind: .quote, isCollapsed: isCollapsed), range: range)
|
||||
default:
|
||||
break
|
||||
}
|
||||
@@ -219,12 +219,12 @@ public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEnti
|
||||
if let language, !language.isEmpty {
|
||||
title = NSAttributedString(string: language.capitalized, font: boldFont.withSize(round(boldFont.pointSize * 0.8235294117647058)), textColor: codeBlockTitleColor)
|
||||
}
|
||||
string.addAttribute(NSAttributedString.Key(rawValue: "Attribute__Blockquote"), value: TextNodeBlockQuoteData(kind: .code(language: language), title: title, color: codeBlockAccentColor, secondaryColor: nil, tertiaryColor: nil, backgroundColor: codeBlockBackgroundColor), range: range)
|
||||
string.addAttribute(NSAttributedString.Key(rawValue: "Attribute__Blockquote"), value: TextNodeBlockQuoteData(kind: .code(language: language), title: title, color: codeBlockAccentColor, secondaryColor: nil, tertiaryColor: nil, backgroundColor: codeBlockBackgroundColor, isCollapsible: false), range: range)
|
||||
}
|
||||
case .BlockQuote:
|
||||
case let .BlockQuote(isCollapsed):
|
||||
addFontAttributes(range, .blockQuote)
|
||||
|
||||
string.addAttribute(NSAttributedString.Key(rawValue: "Attribute__Blockquote"), value: TextNodeBlockQuoteData(kind: .quote, title: nil, color: baseQuoteTintColor, secondaryColor: baseQuoteSecondaryTintColor, tertiaryColor: baseQuoteTertiaryTintColor, backgroundColor: baseQuoteTintColor.withMultipliedAlpha(0.1)), range: range)
|
||||
string.addAttribute(NSAttributedString.Key(rawValue: "Attribute__Blockquote"), value: TextNodeBlockQuoteData(kind: .quote, title: nil, color: baseQuoteTintColor, secondaryColor: baseQuoteSecondaryTintColor, tertiaryColor: baseQuoteTertiaryTintColor, backgroundColor: baseQuoteTintColor.withMultipliedAlpha(0.1), isCollapsible: isCollapsed), range: range)
|
||||
case .BankCard:
|
||||
string.addAttribute(NSAttributedString.Key.foregroundColor, value: linkColor, range: range)
|
||||
if underlineLinks && underlineAllLinks {
|
||||
|
||||
Reference in New Issue
Block a user