compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

TextField's maxLines is ignored when pasting text

Open JetpackDuba opened this issue 4 years ago • 1 comments

Here goes a weird issue: When a TextField has a maxLines limit you simply can't add new lines by hitting the enter key. However, you can copy and paste a text with multiple lines. The weird part here is that it seems that everything is pasted in a single line which has it's own "scroll".

It's easier to understand with some GIFs.

Example without maxLines (works nicely): without_max_lines

Example with maxLines = 1 (weird behavior): with_max_lines

Taking Intellij IDEA as an example of how it should behave (I've tried with a couple of random fields), if (pastedTextLines) > (maxLines - currentLineNumber) the last line should contain all the "overflowing" lines in a single one by removing the new lines character (not sure if it's possible to keep it while still having it in a single line).

Test code:

var textFieldValue by remember { mutableStateOf("") }
MaterialTheme {
    Column {
        OutlinedTextField(
            value = textFieldValue,
            onValueChange = {
                textFieldValue = it
            },
            modifier = Modifier.size(200.dp),
            maxLines = 1,
        )
        OutlinedTextField(
            value = textFieldValue,
            onValueChange = {
                textFieldValue = it
            },
            maxLines = 1,
        )
    }
}

JetpackDuba avatar Nov 29 '21 17:11 JetpackDuba

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

okushnikov avatar Aug 26 '24 16:08 okushnikov