mirror of
https://github.com/bitwarden/android.git
synced 2024-12-18 07:11:51 +03:00
PM-14044: Fix line-breaking logic (#4218)
This commit is contained in:
parent
51e299998f
commit
2eb41e932b
1 changed files with 9 additions and 8 deletions
|
@ -21,7 +21,7 @@ import kotlin.math.floor
|
||||||
* This character takes up no space but can be used to ensure a string is not empty. It can also
|
* This character takes up no space but can be used to ensure a string is not empty. It can also
|
||||||
* be used to insert "safe" line-break positions in a string.
|
* be used to insert "safe" line-break positions in a string.
|
||||||
*
|
*
|
||||||
* Note: Is a string only contains this charactor, it is _not_ considered blank.
|
* Note: Is a string only contains this character, it is _not_ considered blank.
|
||||||
*/
|
*/
|
||||||
const val ZERO_WIDTH_CHARACTER: String = "\u200B"
|
const val ZERO_WIDTH_CHARACTER: String = "\u200B"
|
||||||
|
|
||||||
|
@ -126,14 +126,15 @@ fun String.withLineBreaksAtWidth(
|
||||||
): String {
|
): String {
|
||||||
val measurer = rememberTextMeasurer()
|
val measurer = rememberTextMeasurer()
|
||||||
return remember(this, widthPx, monospacedTextStyle) {
|
return remember(this, widthPx, monospacedTextStyle) {
|
||||||
val characterSizePx = measurer
|
if (widthPx > 0 && this.isNotEmpty()) {
|
||||||
.measure("*", monospacedTextStyle)
|
val stringLengthPx = measurer
|
||||||
.size
|
.measure(text = this, softWrap = false, style = monospacedTextStyle)
|
||||||
.width
|
.size
|
||||||
val perLineCharacterLimit = floor(widthPx / characterSizePx).toInt()
|
.width
|
||||||
if (widthPx > 0) {
|
val linesRequired = stringLengthPx / widthPx
|
||||||
|
val charsPerLine = floor(this.length / linesRequired).toInt()
|
||||||
this
|
this
|
||||||
.chunked(perLineCharacterLimit)
|
.chunked(size = charsPerLine)
|
||||||
.joinToString(separator = "\n")
|
.joinToString(separator = "\n")
|
||||||
} else {
|
} else {
|
||||||
this
|
this
|
||||||
|
|
Loading…
Reference in a new issue