H.Kim
H.Kim

Reputation: 595

In Jetpack Compose, the last cursor of a TextField with ParagraphStyle applied is positioned in a new paragraph

@Composable
fun TestInput() {
    var value by remember {
        mutableStateOf(TextFieldValue("Test Test Test"))
    }
    val visibleText = buildAnnotatedString {
        append("Test ")
        withStyle(ParagraphStyle()) {
            append("Test")
        }
        append(" Test")
    }
    BasicTextField(
            modifier = Modifier.width(500.dp),
            value = value,
            onValueChange = {
                value = it
            },
            visualTransformation = VisualTransformation {
                TransformedText(visibleText, OffsetMapping.Identity)
            })

}

@Composable
@Preview(showBackground = true)
fun TestInputPreview() {
    Box {
        TestInput()
    }
}

To adjust the start margin of the paragraph, I want to show a TextField with a custom ParagraphStyle in the middle using a VisualTransformation. Everything else works fine, but I'm having trouble showing the cursor at the end of the paragraph.

enter image description here

Hover the cursor just before the end of the paragraph. It looks as intended.

enter image description here

When I hover the cursor at the end of a paragraph, it moves the cursor to the next paragraph, not the current one.

I suppose this may not be completely incorrect behavior, but it's not what I intended anyway.

Is there any way to make the cursor move to the very end of the paragraph?

Upvotes: 0

Views: 47

Answers (0)

Related Questions