forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't crash, and allow selection in SelectionContainer to start when …
…drag starts below the bounds of the visible text (#1230)
- Loading branch information
Showing
3 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...src/skikoTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Selection?>(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() | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters