URLS can only take 23 characters (#296)
* URLS can only take 23 characters * Remove hardcoded length of URL
This commit is contained in:
parent
1e29bd668d
commit
fe1d886b62
|
@ -201,7 +201,7 @@ struct StatusEditorAccessoryView: View {
|
|||
}
|
||||
|
||||
private var characterCountView: some View {
|
||||
Text("\((currentInstance.instance?.configuration?.statuses.maxCharacters ?? 500) - viewModel.statusText.string.utf16.count - viewModel.spoilerTextCount)")
|
||||
Text("\((currentInstance.instance?.configuration?.statuses.maxCharacters ?? 500) + viewModel.statusTextCharacterLength)")
|
||||
.foregroundColor(.gray)
|
||||
.font(.scaledCallout)
|
||||
}
|
||||
|
|
|
@ -21,10 +21,17 @@ public class StatusEditorViewModel: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
var spoilerTextCount: Int {
|
||||
private var urlLengthAdjustments: Int = 0
|
||||
private let maxLengthOfUrl = 23
|
||||
|
||||
private var spoilerTextCount: Int {
|
||||
spoilerOn ? spoilerText.utf16.count : 0
|
||||
}
|
||||
|
||||
var statusTextCharacterLength: Int {
|
||||
urlLengthAdjustments - statusText.string.utf16.count - spoilerTextCount
|
||||
}
|
||||
|
||||
@Published var backupStatusText: NSAttributedString?
|
||||
|
||||
@Published var showPoll: Bool = false
|
||||
|
@ -259,13 +266,23 @@ public class StatusEditorViewModel: ObservableObject {
|
|||
resetAutoCompletion()
|
||||
}
|
||||
|
||||
var totalUrlLength = 0
|
||||
var numUrls = 0
|
||||
|
||||
for range in urlRanges {
|
||||
if range.length > maxLengthOfUrl {
|
||||
numUrls += 1
|
||||
totalUrlLength += range.length
|
||||
}
|
||||
|
||||
statusText.addAttributes([.foregroundColor: UIColor(theme?.tintColor ?? .brand),
|
||||
.underlineStyle: NSUnderlineStyle.single.rawValue,
|
||||
.underlineColor: UIColor(theme?.tintColor ?? .brand)],
|
||||
range: NSRange(location: range.location, length: range.length))
|
||||
}
|
||||
|
||||
urlLengthAdjustments = totalUrlLength - (maxLengthOfUrl * numUrls)
|
||||
|
||||
var mediaAdded = false
|
||||
statusText.enumerateAttribute(.attachment, in: range) { attachment, range, _ in
|
||||
if let attachment = attachment as? NSTextAttachment, let image = attachment.image {
|
||||
|
|
Loading…
Reference in New Issue