mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Search filters fixes
This commit is contained in:
@@ -964,7 +964,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
|
||||
attributedText = NSAttributedString(string: foldLineBreaks(embeddedState.text.string.replacingOccurrences(of: "\n\n", with: " ")), font: textFont, textColor: theme.messageTextColor)
|
||||
} else if let message = messages.last {
|
||||
let composedString: NSMutableAttributedString
|
||||
var composedString: NSMutableAttributedString
|
||||
if let inlineAuthorPrefix = inlineAuthorPrefix {
|
||||
composedString = NSMutableAttributedString()
|
||||
composedString.append(NSAttributedString(string: "\(inlineAuthorPrefix): ", font: textFont, textColor: theme.titleColor))
|
||||
@@ -984,13 +984,26 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
chatListSearchResult = nil
|
||||
}
|
||||
|
||||
if let chatListSearchResult = chatListSearchResult {
|
||||
if let chatListSearchResult = chatListSearchResult, let firstRange = chatListSearchResult.resultRanges.first {
|
||||
for range in chatListSearchResult.resultRanges {
|
||||
let stringRange = NSRange(range, in: chatListSearchResult.text)
|
||||
if stringRange.location >= 0 && stringRange.location + stringRange.length <= composedString.length {
|
||||
composedString.addAttribute(.foregroundColor, value: theme.messageHighlightedTextColor, range: stringRange)
|
||||
}
|
||||
}
|
||||
|
||||
let firstRangeOrigin = chatListSearchResult.text.distance(from: chatListSearchResult.text.startIndex, to: firstRange.lowerBound)
|
||||
if firstRangeOrigin > 24 {
|
||||
var leftOrigin: Int = 0
|
||||
(composedString.string as NSString).enumerateSubstrings(in: NSMakeRange(0, firstRangeOrigin), options: [.byWords, .reverse]) { (str, range1, _, _) in
|
||||
let distanceFromEnd = firstRangeOrigin - range1.location
|
||||
if (distanceFromEnd > 12 || range1.location == 0) && leftOrigin == 0 {
|
||||
leftOrigin = range1.location
|
||||
}
|
||||
}
|
||||
composedString = composedString.attributedSubstring(from: NSMakeRange(leftOrigin, composedString.length - leftOrigin)).mutableCopy() as! NSMutableAttributedString
|
||||
composedString.insert(NSAttributedString(string: "\u{2026}", attributes: [NSAttributedString.Key.font: textFont, NSAttributedString.Key.foregroundColor: theme.messageTextColor]), at: 0)
|
||||
}
|
||||
}
|
||||
|
||||
attributedText = composedString
|
||||
@@ -2061,19 +2074,3 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
private func foldLineBreaks(_ text: String) -> String {
|
||||
let lines = text.split { $0.isNewline }
|
||||
var result = ""
|
||||
for line in lines {
|
||||
if line.isEmpty {
|
||||
continue
|
||||
}
|
||||
if result.isEmpty {
|
||||
result += line
|
||||
} else {
|
||||
result += " " + line
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user