Don't crash on invalid highlight range

This commit is contained in:
Peter 2019-10-29 00:10:14 +04:00
parent 9cdeb71e8d
commit f46418534f

View File

@ -860,7 +860,10 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
if let chatListSearchResult = chatListSearchResult {
for range in chatListSearchResult.resultRanges {
composedString.addAttribute(.foregroundColor, value: theme.messageHighlightedTextColor, range: NSRange(range, in: chatListSearchResult.text))
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)
}
}
}