@@ -407,6 +407,7 @@ public class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDeleg
407407 public var customSendIsDisabled : Bool = false
408408 public var customInputTextMaxLength : Int ?
409409 public var customSwitchToKeyboard : ( ( ) -> Void ) ?
410+ public var allowConsecutiveNewlines = true
410411
411412 private var starReactionButton : ComponentView < Empty > ?
412413 private var liveMicrophoneButton : ComponentView < Empty > ?
@@ -4952,24 +4953,41 @@ public class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDeleg
49524953 }
49534954 }
49544955 }
4955-
4956+
4957+ let string = NSMutableAttributedString ( attributedString: editableTextNode. attributedText ?? NSAttributedString ( ) )
4958+ var textColor : UIColor = . black
4959+ var accentTextColor : UIColor = . blue
4960+ var baseFontSize : CGFloat = 17.0
4961+ if let presentationInterfaceState = self . presentationInterfaceState {
4962+ textColor = presentationInterfaceState. theme. chat. inputPanel. inputTextColor
4963+ accentTextColor = presentationInterfaceState. theme. chat. inputPanel. panelControlAccentColor
4964+ baseFontSize = max ( minInputFontSize, presentationInterfaceState. fontSize. baseDisplaySize)
4965+ if " " . isEmpty {
4966+ baseFontSize = 17.0
4967+ }
4968+ }
4969+ let cleanReplacementString = textAttributedStringForStateText ( context: context, stateText: NSAttributedString ( string: cleanText) , fontSize: baseFontSize, textColor: textColor, accentTextColor: accentTextColor, writingDirection: nil , spoilersRevealed: self . spoilersRevealed, availableEmojis: ( self . context? . animatedEmojiStickersValue. keys) . flatMap ( Set . init) ?? Set ( ) , emojiViewProvider: self . emojiViewProvider, makeCollapsedQuoteAttachment: { text, attributes in
4970+ return ChatInputTextCollapsedQuoteAttachmentImpl ( text: text, attributes: attributes)
4971+ } )
4972+ string. replaceCharacters ( in: range, with: cleanReplacementString)
4973+
4974+ var resetText = false
49564975 if cleanText != text {
4957- let string = NSMutableAttributedString ( attributedString : editableTextNode . attributedText ?? NSAttributedString ( ) )
4958- var textColor : UIColor = . black
4959- var accentTextColor : UIColor = . blue
4960- var baseFontSize : CGFloat = 17.0
4961- if let presentationInterfaceState = self . presentationInterfaceState {
4962- textColor = presentationInterfaceState . theme . chat . inputPanel . inputTextColor
4963- accentTextColor = presentationInterfaceState . theme . chat . inputPanel . panelControlAccentColor
4964- baseFontSize = max ( minInputFontSize , presentationInterfaceState . fontSize . baseDisplaySize )
4965- if " " . isEmpty {
4966- baseFontSize = 17.0
4976+ resetText = true
4977+ }
4978+
4979+ if ! self . allowConsecutiveNewlines {
4980+ while string . string . range ( of : " \n \n " ) != nil {
4981+ if let range = string . string . range ( of : " \n \n " ) {
4982+ let rawRange = NSRange ( range , in : string . string )
4983+ let firstNewline = string . attributedSubstring ( from : NSRange ( location : rawRange . location , length : 1 ) )
4984+ string . replaceCharacters ( in : rawRange , with : firstNewline )
4985+ resetText = true
49674986 }
49684987 }
4969- let cleanReplacementString = textAttributedStringForStateText ( context: context, stateText: NSAttributedString ( string: cleanText) , fontSize: baseFontSize, textColor: textColor, accentTextColor: accentTextColor, writingDirection: nil , spoilersRevealed: self . spoilersRevealed, availableEmojis: ( self . context? . animatedEmojiStickersValue. keys) . flatMap ( Set . init) ?? Set ( ) , emojiViewProvider: self . emojiViewProvider, makeCollapsedQuoteAttachment: { text, attributes in
4970- return ChatInputTextCollapsedQuoteAttachmentImpl ( text: text, attributes: attributes)
4971- } )
4972- string. replaceCharacters ( in: range, with: cleanReplacementString)
4988+ }
4989+
4990+ if resetText {
49734991 self . textInputNode? . attributedText = string
49744992 self . textInputNode? . selectedRange = NSMakeRange ( range. lowerBound + cleanReplacementString. length, 0 )
49754993 self . updateTextNodeText ( animated: true )
0 commit comments