Skip to content
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

Cursor in empty BasicTextField only on Left (Start) side on Linux when TextAlign is on Right (End) side #2711

Closed
GazimSoliev opened this issue Feb 6, 2023 · 7 comments · Fixed by JetBrains/compose-multiplatform-core#1354
Assignees
Labels
bug Something isn't working input Touch, mouse, keyboard input related reproduced text

Comments

@GazimSoliev
Copy link

Cursor in empty BasicTextField only on Left (Start) side on Linux when TextAlign is on Right (End) side

Compose: 1.3.0
Kotlin: 1.8.0
OS: 6.1.9-1-MANJARO
Architecture: x86

On Linux:
image
If write something:
image

On Android:
image
If write something:
image

@pjBooms pjBooms added the bug Something isn't working label Feb 7, 2023
@pjBooms
Copy link
Collaborator

pjBooms commented Feb 7, 2023

Thank you for your report! It would be great, if you could attach the reproducing sample not only the screenshot so we would not need to make it from the screenshot.

@pjBooms pjBooms removed their assignment Feb 7, 2023
@igordmn igordmn added input Touch, mouse, keyboard input related text labels Feb 7, 2023
@igordmn igordmn assigned eymar and unassigned igordmn Feb 7, 2023
@igordmn
Copy link
Collaborator

igordmn commented Feb 7, 2023

Reproduces on Windows too

import androidx.compose.material.TextField
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.window.singleWindowApplication

fun main() = singleWindowApplication {
    var text by remember { mutableStateOf("") }
    TextField(text, { text = it }, textStyle = TextStyle.Default.copy(textAlign = TextAlign.End))
}

@GazimSoliev
Copy link
Author

Thank you for your report! It would be great, if you could attach the reproducing sample not only the screenshot so we would not need to make it from the screenshot.

AppTheme {
    Surface(Modifier.fillMaxSize()) {
                Box(contentAlignment = Alignment.Center) {
                    var text by remember {
                        mutableStateOf(TextFieldValue())
                    }
                    BasicTextField(
                        modifier = Modifier
                            .height(100.dp).width(300.dp)
                            .background(Color.Yellow).padding(32.dp),
                        value = text, onValueChange = {
                            text = it
                        }, textStyle = TextStyle.Default.copy(textAlign = TextAlign.Right)
                    )
                }
            }
}

@mahozad
Copy link
Contributor

mahozad commented Aug 2, 2023

Center alignment in desktop has this problem too.
When field becomes empty, the cursor goes to the left instead of staying at the center:

BasicTextField(
            value = "",
            onValueChange = {},
            textStyle = LocalTextStyle.current.copy(
                textAlign = TextAlign.Center
            ),

@gutnikvk
Copy link

gutnikvk commented Jun 7, 2024

Any updates on this? Still reproducing on Compose 1.6.2.

@MatkovIvan
Copy link
Member

Should be fixed by JetBrains/compose-multiplatform-core#1354

mazunin-v-jb added a commit to JetBrains/compose-multiplatform-core that referenced this issue Jun 11, 2024
…set explicitly (#1354)

After focusing on the textfield and before entering any text, now
blinking cursor will be positioned in accordance with TextAlignment.

Fixes https://youtrack.jetbrains.com/issue/COMPOSE-1360/
Fixes JetBrains/compose-multiplatform#2711
Fixes JetBrains/compose-multiplatform#3098
Fixes JetBrains/compose-multiplatform#4611

## Testing
Manual testing.

## Release Notes
<!--
Optional, if omitted - won't be included in the changelog

Sections:
- Highlights
- Known issues
- Breaking changes
- Features
- Fixes

Subsections:
- Multiple Platforms
- iOS
- Desktop
- Web
- Resources
- Gradle Plugin
-->
### Fixes - Multiple Platforms
- Fix initial cursor position in the empty `TextField` with explicitly
set `TextAlignment`.

## Google CLA
You need to sign the Google Contributor’s License Agreement at
https://cla.developers.google.com/.
This is needed since we synchronise most of the code with Google’s AOSP
repository. Signing this agreement allows us to synchronise code from
your Pull Requests as well.

---------

Co-authored-by: Ivan Matkov <ivan.matkov@jetbrains.com>
@okushnikov
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working input Touch, mouse, keyboard input related reproduced text
Projects
None yet
8 participants