From 2c5886b3eead4af25b109d43afe74b093fc2d189 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Sat, 19 Oct 2019 16:16:55 +0400 Subject: [PATCH] Maybe one line is ok --- .../Sources/Node/ChatListItem.swift | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/submodules/ChatListUI/Sources/Node/ChatListItem.swift b/submodules/ChatListUI/Sources/Node/ChatListItem.swift index 3804fa1e17..3238fc2dca 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItem.swift @@ -824,31 +824,12 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { } } - func foldLineBreaks(_ text: String, allowTwoLines: Bool) -> String { - var lines = text.split { $0.isNewline } - var startedBothLines = false - var result = "" - for line in lines { - if result.isEmpty { - result += line - } else { - if allowTwoLines && !startedBothLines { - result += "\n" + line - startedBothLines = true - } else { - result += " " + line - } - } - } - return result - } - let messageText: String if let currentChatListText = currentChatListText, currentChatListText.0 == text { messageText = currentChatListText.1 chatListText = currentChatListText } else { - messageText = foldLineBreaks(text, allowTwoLines: peerText == nil) + messageText = foldLineBreaks(text) chatListText = (text, messageText) } @@ -856,7 +837,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { hasDraft = true authorAttributedString = NSAttributedString(string: item.presentationData.strings.DialogList_Draft, font: textFont, textColor: theme.messageDraftTextColor) - attributedText = NSAttributedString(string: foldLineBreaks(embeddedState.text.string.replacingOccurrences(of: "\n\n", with: " "), allowTwoLines: false), font: textFont, textColor: theme.messageTextColor) + attributedText = NSAttributedString(string: foldLineBreaks(embeddedState.text.string.replacingOccurrences(of: "\n\n", with: " ")), font: textFont, textColor: theme.messageTextColor) } else if let message = message { let composedString: NSMutableAttributedString if let inlineAuthorPrefix = inlineAuthorPrefix { @@ -1838,3 +1819,20 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { } } } + +private func foldLineBreaks(_ text: String) -> String { + var lines = text.split { $0.isNewline } + var startedBothLines = false + var result = "" + for line in lines { + if line.isEmpty { + continue + } + if result.isEmpty { + result += line + } else { + result += " " + line + } + } + return result +}