diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/MultiWidgetSelectionDelegate.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/MultiWidgetSelectionDelegate.kt index f14b7677ca540..407dae68ae5cf 100644 --- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/MultiWidgetSelectionDelegate.kt +++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/MultiWidgetSelectionDelegate.kt @@ -217,8 +217,8 @@ internal fun SelectionLayoutBuilder.appendSelectableInfo( val bounds = Rect( 0.0f, 0.0f, - textLayoutResult.multiParagraph.width.toFloat(), - textLayoutResult.multiParagraph.height.toFloat() + textLayoutResult.size.width.toFloat(), + textLayoutResult.size.height.toFloat() ) val currentXDirection = getXDirection(localPosition, bounds) diff --git a/compose/foundation/foundation/src/skikoTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerTest.kt b/compose/foundation/foundation/src/skikoTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerTest.kt new file mode 100644 index 0000000000000..9ad70f3ed0c53 --- /dev/null +++ b/compose/foundation/foundation/src/skikoTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerTest.kt @@ -0,0 +1,71 @@ +/* + * Copyright 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package androidx.compose.foundation.text.selection + +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.text.BasicText +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.dragAndDrop +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.performMouseInput +import androidx.compose.ui.test.runComposeUiTest +import androidx.compose.ui.text.TextRange +import androidx.compose.ui.unit.dp +import kotlin.test.Test +import kotlin.test.assertEquals + +@OptIn(ExperimentalTestApi::class) +class SelectionContainerTest { + @Test + fun selectionWorksWhenDraggingFromBelowText() = runComposeUiTest { + var selection by mutableStateOf(null) + val text = "Line 1\nLine2" + setContent { + SelectionContainer( + modifier = Modifier.size(500.dp).testTag("selection_container"), + selection = selection, + onSelectionChange = { + selection = it + } + ) { + BasicText( + text = text, + modifier = Modifier.fillMaxSize() + ) + } + } + + onNodeWithTag("selection_container").performMouseInput { + dragAndDrop( + start = Offset(250f, 499f), + end = Offset.Zero + ) + } + + assertEquals( + expected = TextRange(text.length, 0), + actual = selection?.toTextRange() + ) + } +} \ No newline at end of file diff --git a/compose/ui/ui/src/skikoTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerTest.kt b/compose/ui/ui/src/skikoTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerUiTest.kt similarity index 98% rename from compose/ui/ui/src/skikoTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerTest.kt rename to compose/ui/ui/src/skikoTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerUiTest.kt index b9c57278fe4cf..768d4cb741747 100644 --- a/compose/ui/ui/src/skikoTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerTest.kt +++ b/compose/ui/ui/src/skikoTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerUiTest.kt @@ -38,7 +38,7 @@ import kotlin.test.assertEquals * is that [PointerIconService] is needed for some of the tests, and it is internal in `ui`. */ @OptIn(ExperimentalTestApi::class) -class SelectionContainerTest { +class SelectionContainerUiTest { @Test fun selectionContainerSetsTextPointerIcon() = runComposeUiTest { lateinit var pointerIconService: PointerIconService