mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Filter variation selectors from shortName field
This commit is contained in:
parent
6e6de4da64
commit
7fec53f5d0
2 changed files with 18 additions and 2 deletions
|
|
@ -90,4 +90,15 @@ extension String {
|
|||
let end = index(start, offsetBy: range.upperBound - range.lowerBound)
|
||||
return String(self[start ..< end])
|
||||
}
|
||||
|
||||
// Filter out variation selectors from the string
|
||||
var withoutVariationSelectors: String {
|
||||
return self.unicodeScalars
|
||||
.filter { scalar in
|
||||
return !scalar.properties.isVariationSelector
|
||||
}
|
||||
.compactMap { UnicodeScalar($0) }
|
||||
.map { String($0) }
|
||||
.joined()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,11 +75,16 @@ struct UserConfig: View {
|
|||
TextField("Short Name", text: $shortName)
|
||||
.foregroundColor(.gray)
|
||||
.onChange(of: shortName) {
|
||||
var totalBytes = shortName.utf8.count
|
||||
let newValue = shortName.withoutVariationSelectors
|
||||
let totalBytes = newValue.utf8.count
|
||||
// Only mess with the value if it is too big
|
||||
if totalBytes > 4 {
|
||||
// If too long, drop the last thing entered
|
||||
shortName = String(shortName.dropLast())
|
||||
totalBytes = shortName.utf8.count
|
||||
} else if shortName != newValue {
|
||||
// If not too long, make sure the stripped
|
||||
// variant is placed back in text field if necessary
|
||||
shortName = newValue
|
||||
}
|
||||
}
|
||||
.foregroundColor(.gray)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue