PM-42349: bug: Hide static password mask when field is blank (#7376)

This commit is contained in:
David Perez authored and GitHub committed 2026-09-10 13:58:58 +00:00
1 parent e02593a5a5
commit 16e5ee2c04
1 file changed
+8 -5
@@ -6,10 +6,12 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.TransformedText
import androidx.compose.ui.text.input.VisualTransformation
import com.bitwarden.ui.platform.base.util.toAnnotatedString
/**
* Returns a [VisualTransformation] that masks text with [mask]. When [staticCharacterCount] is
* non-null, the transformed text always contains that number of mask characters.
* non-null and the text is non-empty, the transformed text contains that number of mask
* characters. Blank text is never masked.
*/
@Composable
fun passwordVisualTransformation(
@@ -30,10 +32,11 @@ private class BitwardenPasswordVisualTransformation(
override fun filter(
text: AnnotatedString,
): TransformedText = TransformedText(
AnnotatedString(
mask.toString().repeat(n = staticCharacterCount ?: text.text.length),
),
object : OffsetMapping {
text = mask
.toString()
.repeat(staticCharacterCount?.takeIf { text.text.isNotEmpty() } ?: text.text.length)
.toAnnotatedString(),
offsetMapping = object : OffsetMapping {
override fun originalToTransformed(
offset: Int,
): Int = staticCharacterCount?.let { offset.coerceAtMost(it) } ?: offset