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

Fix the pointer icon in SelectionContainer #1014

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

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())
}
}