Limit the text length in the 'in reply to' preview (#4491)
* Limit the text length in the 'in reply to' preview Otherwise, very long texts with no line breaks can cause a Compose crash
This commit is contained in:
committed by
GitHub
parent
338267d4e3
commit
f59b26eb10
@@ -98,3 +98,22 @@ fun String.ensureEndsLeftToRight() = if (containsRtLOverride()) "$this$LTR_OVERR
|
||||
fun String.containsRtLOverride() = contains(RTL_OVERRIDE_CHAR)
|
||||
|
||||
fun String.filterDirectionOverrides() = filterNot { it == RTL_OVERRIDE_CHAR || it == LTR_OVERRIDE_CHAR }
|
||||
|
||||
/**
|
||||
* This works around https://github.com/element-hq/element-x-android/issues/2105.
|
||||
* @param maxLength Max characters to retrieve. Defaults to `500`.
|
||||
* @param ellipsize Whether to add an ellipsis (`…`) char at the end or not. Defaults to `false`.
|
||||
* @return The string truncated to [maxLength] characters, with an optional ellipsis if larger.
|
||||
*/
|
||||
fun String.toSafeLength(
|
||||
maxLength: Int = 500,
|
||||
ellipsize: Boolean = false,
|
||||
): String {
|
||||
return if (ellipsize) {
|
||||
ellipsize(maxLength)
|
||||
} else if (length > maxLength) {
|
||||
take(maxLength)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user