mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix poll text limits
This commit is contained in:
parent
c5165b03ac
commit
53f37cd043
@ -657,6 +657,7 @@ final class ComposePollScreenComponent: Component {
|
||||
},
|
||||
assumeIsEditing: self.inputMediaNodeTargetTag === self.pollTextFieldTag,
|
||||
characterLimit: component.initialData.maxPollTextLength,
|
||||
emptyLineHandling: .allowed,
|
||||
returnKeyAction: { [weak self] in
|
||||
guard let self else {
|
||||
return
|
||||
@ -751,6 +752,7 @@ final class ComposePollScreenComponent: Component {
|
||||
},
|
||||
assumeIsEditing: self.inputMediaNodeTargetTag === pollOption.textFieldTag,
|
||||
characterLimit: component.initialData.maxPollOptionLength,
|
||||
emptyLineHandling: .notAllowed,
|
||||
returnKeyAction: { [weak self] in
|
||||
guard let self else {
|
||||
return
|
||||
@ -1132,6 +1134,7 @@ final class ComposePollScreenComponent: Component {
|
||||
},
|
||||
assumeIsEditing: self.inputMediaNodeTargetTag === self.quizAnswerTextInputTag,
|
||||
characterLimit: component.initialData.maxPollTextLength,
|
||||
emptyLineHandling: .allowed,
|
||||
returnKeyAction: { [weak self] in
|
||||
guard let self else {
|
||||
return
|
||||
@ -1564,7 +1567,7 @@ public class ComposePollScreen: ViewControllerComponentContainer, AttachmentCont
|
||||
|
||||
public static func initialData(context: AccountContext) -> InitialData {
|
||||
return InitialData(
|
||||
maxPollTextLength: Int(context.userLimits.maxCaptionLength),
|
||||
maxPollTextLength: Int(255),
|
||||
maxPollOptionLength: 100
|
||||
)
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ public final class ListComposePollOptionComponent: Component {
|
||||
public let resetText: ResetText?
|
||||
public let assumeIsEditing: Bool
|
||||
public let characterLimit: Int?
|
||||
public let emptyLineHandling: TextFieldComponent.EmptyLineHandling
|
||||
public let returnKeyAction: (() -> Void)?
|
||||
public let backspaceKeyAction: (() -> Void)?
|
||||
public let selection: Selection?
|
||||
@ -90,6 +91,7 @@ public final class ListComposePollOptionComponent: Component {
|
||||
resetText: ResetText? = nil,
|
||||
assumeIsEditing: Bool = false,
|
||||
characterLimit: Int,
|
||||
emptyLineHandling: TextFieldComponent.EmptyLineHandling,
|
||||
returnKeyAction: (() -> Void)?,
|
||||
backspaceKeyAction: (() -> Void)?,
|
||||
selection: Selection?,
|
||||
@ -104,6 +106,7 @@ public final class ListComposePollOptionComponent: Component {
|
||||
self.resetText = resetText
|
||||
self.assumeIsEditing = assumeIsEditing
|
||||
self.characterLimit = characterLimit
|
||||
self.emptyLineHandling = emptyLineHandling
|
||||
self.returnKeyAction = returnKeyAction
|
||||
self.backspaceKeyAction = backspaceKeyAction
|
||||
self.selection = selection
|
||||
@ -134,6 +137,9 @@ public final class ListComposePollOptionComponent: Component {
|
||||
if lhs.characterLimit != rhs.characterLimit {
|
||||
return false
|
||||
}
|
||||
if lhs.emptyLineHandling != rhs.emptyLineHandling {
|
||||
return false
|
||||
}
|
||||
if lhs.selection != rhs.selection {
|
||||
return false
|
||||
}
|
||||
@ -325,7 +331,7 @@ public final class ListComposePollOptionComponent: Component {
|
||||
},
|
||||
isOneLineWhenUnfocused: false,
|
||||
characterLimit: component.characterLimit,
|
||||
emptyLineHandling: .notAllowed,
|
||||
emptyLineHandling: component.emptyLineHandling,
|
||||
formatMenuAvailability: .none,
|
||||
returnKeyType: .next,
|
||||
lockedFormatAction: {
|
||||
|
@ -609,12 +609,34 @@ public final class TextFieldComponent: Component {
|
||||
}
|
||||
|
||||
if let characterLimit = component.characterLimit {
|
||||
let replacementString = text as NSString
|
||||
let string = self.inputState.inputText.string as NSString
|
||||
let updatedString = string.replacingCharacters(in: range, with: text)
|
||||
if (updatedString as NSString).length > characterLimit {
|
||||
let deltaLength = replacementString.length - range.length
|
||||
let resultingLength = string.length + deltaLength
|
||||
if resultingLength > characterLimit {
|
||||
let availableLength = characterLimit - string.length
|
||||
if availableLength > 0 {
|
||||
var insertString = replacementString.substring(to: availableLength)
|
||||
|
||||
switch component.emptyLineHandling {
|
||||
case .allowed:
|
||||
break
|
||||
case .oneConsecutive:
|
||||
while insertString.range(of: "\n\n") != nil {
|
||||
if let range = insertString.range(of: "\n\n") {
|
||||
insertString.replaceSubrange(range, with: "\n")
|
||||
}
|
||||
}
|
||||
case .notAllowed:
|
||||
insertString = insertString.replacingOccurrences(of: "\n", with: "")
|
||||
}
|
||||
|
||||
self.insertText(NSAttributedString(string: insertString))
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
if text.count != 0 {
|
||||
switch component.emptyLineHandling {
|
||||
case .allowed:
|
||||
break
|
||||
@ -630,12 +652,15 @@ public final class TextFieldComponent: Component {
|
||||
return false
|
||||
}
|
||||
|
||||
let string = self.inputState.inputText.string as NSString
|
||||
let updatedString = string.replacingCharacters(in: range, with: text)
|
||||
if updatedString.range(of: "\n") != nil {
|
||||
if text.range(of: "\n") != nil {
|
||||
let updatedText = text.replacingOccurrences(of: "\n", with: "")
|
||||
if !updatedText.isEmpty {
|
||||
self.insertText(NSAttributedString(string: updatedText))
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user