Business fixes

This commit is contained in:
Isaac
2024-03-05 15:32:59 +04:00
parent ae998eb91e
commit 7966993955
26 changed files with 503 additions and 105 deletions

View File

@@ -97,6 +97,7 @@ public final class TextFieldComponent: Component {
public let resetText: NSAttributedString?
public let isOneLineWhenUnfocused: Bool
public let characterLimit: Int?
public let allowEmptyLines: Bool
public let formatMenuAvailability: FormatMenuAvailability
public let lockedFormatAction: () -> Void
public let present: (ViewController) -> Void
@@ -114,6 +115,7 @@ public final class TextFieldComponent: Component {
resetText: NSAttributedString?,
isOneLineWhenUnfocused: Bool,
characterLimit: Int? = nil,
allowEmptyLines: Bool = true,
formatMenuAvailability: FormatMenuAvailability,
lockedFormatAction: @escaping () -> Void,
present: @escaping (ViewController) -> Void,
@@ -130,6 +132,7 @@ public final class TextFieldComponent: Component {
self.resetText = resetText
self.isOneLineWhenUnfocused = isOneLineWhenUnfocused
self.characterLimit = characterLimit
self.allowEmptyLines = allowEmptyLines
self.formatMenuAvailability = formatMenuAvailability
self.lockedFormatAction = lockedFormatAction
self.present = present
@@ -167,6 +170,9 @@ public final class TextFieldComponent: Component {
if lhs.characterLimit != rhs.characterLimit {
return false
}
if lhs.allowEmptyLines != rhs.allowEmptyLines {
return false
}
if lhs.formatMenuAvailability != rhs.formatMenuAvailability {
return false
}
@@ -553,6 +559,13 @@ public final class TextFieldComponent: Component {
return false
}
}
if !component.allowEmptyLines {
let string = self.inputState.inputText.string as NSString
let updatedString = string.replacingCharacters(in: range, with: text)
if updatedString.range(of: "\n\n") != nil {
return false
}
}
return true
}