forked from shadowfacts/Tusker
Use link replacement length from instance config if available
This commit is contained in:
parent
9f8b14d180
commit
f5e9f71586
|
@ -13,12 +13,12 @@ public struct CharacterCounter {
|
|||
static let linkDetector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
|
||||
static let mention = try! NSRegularExpression(pattern: "(@[a-z0-9_]+)(?:@[a-z0-9\\-\\.]+[a-z0-9]+)?", options: .caseInsensitive)
|
||||
|
||||
public static func count(text: String) -> Int {
|
||||
public static func count(text: String, for instance: Instance? = nil) -> Int {
|
||||
let mentionsRemoved = removeMentions(in: text)
|
||||
var count = mentionsRemoved.count
|
||||
for match in linkDetector.matches(in: mentionsRemoved, options: [], range: NSRange(location: 0, length: mentionsRemoved.utf16.count)) {
|
||||
count -= match.range.length
|
||||
count += 23 // Mastodon link length
|
||||
count += instance?.configuration?.statuses.charactersReservedPerURL ?? 23 // default Mastodon link length
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ struct ComposeView: View {
|
|||
var charactersRemaining: Int {
|
||||
let limit = mastodonController.instance?.maxStatusCharacters ?? 500
|
||||
let cwCount = draft.contentWarningEnabled ? draft.contentWarning.count : 0
|
||||
return limit - (cwCount + CharacterCounter.count(text: draft.text))
|
||||
return limit - (cwCount + CharacterCounter.count(text: draft.text, for: mastodonController.instance))
|
||||
}
|
||||
|
||||
var requiresAttachmentDescriptions: Bool {
|
||||
|
|
Loading…
Reference in New Issue