JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.9k stars 1.16k forks source link

SelectionContainer inside ComposePanel can't select multiple lines #1576

Open vovahost opened 2 years ago

vovahost commented 2 years ago

SelectionContainer doesn't select text correctly across multiple lines.

ComposePanel().apply {
  setContent {
    val customTextSelectionColors = TextSelectionColors(
      handleColor = androidx.compose.ui.graphics.Color.Blue,
      backgroundColor = androidx.compose.ui.graphics.Color.Blue.copy(alpha = 0.4f)
    )
    CompositionLocalProvider(LocalTextSelectionColors provides customTextSelectionColors) {
      SelectionContainer {
        Text(
          text = "Neat own nor she said see walk. And charm add green you these. Sang busy in this drew ye fine. At greater prepare musical so attacks as on distant. Improving age our her cordially intention. His devonshire sufficient precaution say preference middletons insipidity. Since might water hence the her worse. Concluded it offending dejection do earnestly as me direction. Nature played thirty all him. Arrived totally in as between private. Favour of so as on pretty though elinor direct. Reasonable estimating be alteration we themselves entreaties me of reasonably. Direct wished so be expect polite valley. Whose asked stand it sense no spoil to. Prudent you too his conduct feeling limited and. Side he lose paid as hope so face upon be. Goodness did suitable learning put.",
          maxLines = 20,
          textAlign = TextAlign.Start,
          color = MaterialTheme.appColors.onBackground,
          modifier = Modifier
            .padding(
              vertical = 4.dp,
              horizontal = 8.dp,
            )
        )
      }
    }
  }
}

See the video below:

https://user-images.githubusercontent.com/33025410/145708641-7d506747-7e9f-4b29-96f1-eb2e9304d17a.mp4

Also double clicking on a word only expands the selection to that word, but double clicking it again will not expand the selection to the entire container. Just have a look at how text selection expansion using double clicks works in Chrome browser for example.

I'm using Compose 1.0.0-rc10

akurasov commented 2 years ago

Please try Compose 1.0.0. There were Selection fixes in the latest builds before Release

akurasov commented 2 years ago

There is no issue on 1.0.0

fun main() = application {
    Window(onCloseRequest = ::exitApplication) {
        App2()
    }
}

@Composable
fun App2() {
    SelectionContainer {
        Text(
            text = "Neat own nor she said see walk. And charm add green you these. Sang busy in this drew ye fine. At greater prepare musical so attacks as on distant. Improving age our her cordially intention. His devonshire sufficient precaution say preference middletons insipidity. Since might water hence the her worse. Concluded it offending dejection do earnestly as me direction. Nature played thirty all him. Arrived totally in as between private. Favour of so as on pretty though elinor direct. Reasonable estimating be alteration we themselves entreaties me of reasonably. Direct wished so be expect polite valley. Whose asked stand it sense no spoil to. Prudent you too his conduct feeling limited and. Side he lose paid as hope so face upon be. Goodness did suitable learning put.",
            maxLines = 20,
            textAlign = TextAlign.Start,
            modifier = Modifier
                .padding(
                    vertical = 4.dp,
                    horizontal = 8.dp,
                )
        )
    }
}
vovahost commented 2 years ago

@akurasov I just tried your example with the latest version 1.0.1-rc2 and you're right, the bug can't be reproduced but if you try my example with the latest version, you'll notice that the bug is still there. I don't know if it's a bug in SelectionContainer or in ComposePanel. I'll post another example which is easier to run:

class Main {

  companion object {
    @JvmStatic
    fun main(args: Array<String>) {
      EventQueue.invokeLater {
        val frame = JFrame("Simple").also {
          it.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
          it.size = Dimension(616, 739)
          it.setLocationRelativeTo(null)
          it.location = Point(200, 0)
          it.contentPane.background = Color.darkGray
        }
        frame.isVisible = true

        frame.add(
          ComposePanel().apply {
            setContent {
              val customTextSelectionColors = TextSelectionColors(
                handleColor = androidx.compose.ui.graphics.Color.Blue,
                backgroundColor = androidx.compose.ui.graphics.Color.Blue.copy(alpha = 0.4f)
              )
              CompositionLocalProvider(LocalTextSelectionColors provides customTextSelectionColors) {
                SelectionContainer {
                  Text(
                    text = "Neat own nor she said see walk. And charm add green you these. Sang busy in this drew ye fine. At greater prepare musical so attacks as on distant. Improving age our her cordially intention. His devonshire sufficient precaution say preference middletons insipidity. Since might water hence the her worse. Concluded it offending dejection do earnestly as me direction. Nature played thirty all him. Arrived totally in as between private. Favour of so as on pretty though elinor direct. Reasonable estimating be alteration we themselves entreaties me of reasonably. Direct wished so be expect polite valley. Whose asked stand it sense no spoil to. Prudent you too his conduct feeling limited and. Side he lose paid as hope so face upon be. Goodness did suitable learning put.",
                    maxLines = 20,
                    textAlign = TextAlign.Start,
                    color = MaterialTheme.appColors.onBackground,
                    modifier = Modifier
                      .padding(
                        vertical = 4.dp,
                        horizontal = 8.dp,
                      )
                  )
                }
              }
            }
          }
        )
      }
    }
  }
}

I didn't record another video as it's exactly the same as the one I posted. Could you reopen the Issue?

okushnikov commented 2 weeks ago

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