-
Notifications
You must be signed in to change notification settings - Fork 1k
[PM-25423] Force LTR direction for password and sensitive fields #6090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
417726a
Force LTR direction for password and sensitive fields
SaintPatrck 08636a6
Address code review feedback for LTR visual transformations
SaintPatrck 3c86dc3
Fix test failures caused by LTR visual transformation
SaintPatrck 6f368d5
Remove unnecessary `@Suppress("StringTemplate")` in tests
SaintPatrck 5c9be5d
Fix password history visual transformation order
SaintPatrck 9d6189d
Remove unnecessary curly braces
SaintPatrck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
ui/src/main/kotlin/com/bitwarden/ui/platform/components/util/CompoundVisualTransformation.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package com.bitwarden.ui.platform.components.util | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.remember | ||
| 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 | ||
|
|
||
| /** | ||
| * A [VisualTransformation] that chains multiple other [VisualTransformation]s. | ||
| * | ||
| * This is useful for applying multiple transformations to a text field. The | ||
| * transformations are applied in the order they are provided, with each transformation's | ||
| * output becoming the input for the next transformation. | ||
| * | ||
| * ## Example Usage | ||
| * | ||
| * Combining password masking with LTR direction enforcement: | ||
| * ```kotlin | ||
| * val visualTransformation = compoundVisualTransformation( | ||
| * PasswordVisualTransformation(), | ||
| * forceLtrVisualTransformation() | ||
| * ) | ||
| * TextField( | ||
| * value = password, | ||
| * visualTransformation = visualTransformation | ||
| * ) | ||
| * ``` | ||
| * | ||
| * Combining color transformation with LTR for readonly fields: | ||
| * ```kotlin | ||
| * val visualTransformation = compoundVisualTransformation( | ||
| * nonLetterColorVisualTransformation(), | ||
| * forceLtrVisualTransformation() | ||
| * ) | ||
| * ``` | ||
| * | ||
| * ## Important Notes | ||
| * | ||
| * - Offset mapping is correctly composed through all transformations | ||
| * - The order of transformations matters (first applied is first in the list) | ||
| * - Use [compoundVisualTransformation] function for proper `remember` optimization | ||
| * | ||
| * @param transformations The visual transformations to apply in order | ||
| * @see compoundVisualTransformation | ||
| * @see forceLtrVisualTransformation | ||
| */ | ||
| internal class CompoundVisualTransformation( | ||
| vararg val transformations: VisualTransformation, | ||
| ) : VisualTransformation { | ||
| override fun filter(text: AnnotatedString): TransformedText { | ||
| return transformations.fold( | ||
| TransformedText( | ||
| text, | ||
| OffsetMapping.Identity, | ||
| ), | ||
| ) { acc, transformation -> | ||
| val result = transformation.filter(acc.text) | ||
|
|
||
| val composedMapping = object : OffsetMapping { | ||
| override fun originalToTransformed(offset: Int): Int { | ||
| val originalTransformed = acc.offsetMapping.originalToTransformed(offset) | ||
| return result.offsetMapping.originalToTransformed(originalTransformed) | ||
| } | ||
|
|
||
| override fun transformedToOriginal(offset: Int): Int { | ||
| val resultOriginal = result.offsetMapping.transformedToOriginal(offset) | ||
| return acc.offsetMapping.transformedToOriginal(resultOriginal) | ||
| } | ||
| } | ||
| TransformedText(result.text, composedMapping) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Remembers a [CompoundVisualTransformation] for the given [transformations]. | ||
| * | ||
| * This is an optimization to avoid creating a new [CompoundVisualTransformation] on every | ||
| * recomposition. | ||
| */ | ||
| @Composable | ||
| fun compoundVisualTransformation( | ||
| vararg transformations: VisualTransformation, | ||
| ): VisualTransformation = | ||
| remember(*transformations) { | ||
| CompoundVisualTransformation(*transformations) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one can just be
"$LRO${password.password}$PDF"