Skip to content

Commit

Permalink
Fix the pointer icon in SelectionContainer (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-sasha committed Jan 24, 2024
1 parent ee14b93 commit db202d9
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 75 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* 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.
Expand All @@ -18,7 +18,8 @@ package androidx.compose.foundation.text

import androidx.compose.foundation.text.selection.SelectionRegistrar
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerHoverIcon

internal actual fun Modifier.textPointerHoverIcon(
selectionRegistrar: SelectionRegistrar?
): Modifier = this
): Modifier = if (selectionRegistrar == null) this else pointerHoverIcon(textPointerIcon)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@
package androidx.compose.foundation.text

import androidx.compose.ui.input.pointer.PointerIcon
import java.awt.Cursor

internal actual val textPointerIcon: PointerIcon =
PointerIcon(Cursor(Cursor.TEXT_CURSOR))
internal actual val textPointerIcon: PointerIcon = PointerIcon.Text
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ internal class AwtCursor(val cursor: Cursor) : PointerIcon {

other as AwtCursor

if (cursor != other.cursor) return false
// AwtCursor doesn't implement equals
if (cursor.type != other.cursor.type) return false

return true
}

override fun hashCode(): Int {
return cursor.hashCode()
// AwtCursor doesn't implement hashCode
return cursor.type
}

override fun toString(): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.Column
import androidx.compose.foundation.text.BasicText
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.PointerIconService
import androidx.compose.ui.platform.LocalPointerIconService
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performMouseInput
import androidx.compose.ui.test.runComposeUiTest
import kotlin.test.Test
import kotlin.test.assertEquals

/**
* Tests relating to [SelectionContainer].
*
* The reason this test is in the `ui` module, even though [SelectionContainer] is in `foundation`,
* is that [PointerIconService] is needed for some of the tests, and it is internal in `ui`.
*/
@OptIn(ExperimentalTestApi::class)
class SelectionContainerTest {
@Test
fun selectionContainerSetsTextPointerIcon() = runComposeUiTest {
lateinit var pointerIconService: PointerIconService
setContent {
pointerIconService = LocalPointerIconService.current!!
SelectionContainer {
Column {
BasicText(
text = "Text text text text",
modifier = Modifier.testTag("content")
)
}
}
}

onNodeWithTag("content").performMouseInput {
moveTo(Offset(1f, 1f))
}
assertEquals(PointerIcon.Text, pointerIconService.getIcon())
}
}

0 comments on commit db202d9

Please sign in to comment.