Skip to content

Commit

Permalink
Fix displaying spaces in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Dec 12, 2024
1 parent 3589d8d commit 6ee2291
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions HabitRPG/Extensions/Down-Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,12 @@ extension Down {
applyMentions(string, mentions: mentions)
}
applyCustomEmoji(string, size: baseSize)

var range = string.mutableString.range(of: "<br>")
while range.length > 0 {
string.replaceCharacters(in: range, with: "\n")
range = string.mutableString.range(of: "<br>")
}

range = string.mutableString.range(of: "<strong>")
replaceIn(string: string, characters: "<br>", with: "\n")
replaceIn(string: string, characters: "&ensp;", with: "")
replaceIn(string: string, characters: "&emsp;", with: " ")
replaceIn(string: string, characters: "&nbsp;", with: " ")

var range = string.mutableString.range(of: "<strong>")
let scaledBaseSize = UIFontMetrics.default.scaledSystemFont(ofSize: baseSize).pointSize
while range.length > 0 {
string.replaceCharacters(in: range, with: "")
Expand All @@ -102,6 +100,14 @@ extension Down {
}
}

private func replaceIn(string: NSMutableAttributedString, characters: String, with replacement: String) {
var range = string.mutableString.range(of: characters)
while range.length > 0 {
string.replaceCharacters(in: range, with: replacement)
range = string.mutableString.range(of: characters)
}
}

private func applyMentions(_ string: NSMutableAttributedString, mentions: [String]) {
let text = string.mutableString
for mention in mentions {
Expand Down

0 comments on commit 6ee2291

Please sign in to comment.