Skip to content

Commit

Permalink
Fix Accessibility. Crash on text hover on Windows
Browse files Browse the repository at this point in the history
Fixes JetBrains/compose-multiplatform#3742

The fix is cherry-picked from androidx@7a7f57c to jb-main
(it contains other fix as well)

Because we always return `false`, we [have textLayoutResult = null](https://github.com/JetBrains/compose-multiplatform-core/blob/7f72ab8719252acaafc753a9aa28d2940ea995df/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/ComposeAccessible.kt#L116)

It isn't reproducible on macOs because it doesn't call `ComposeAccessibleText.getCharacterBounds`
  • Loading branch information
igordmn committed Sep 29, 2023
1 parent 4ab56b4 commit 4c147e7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Expand Up @@ -199,7 +199,6 @@ internal class TextStringSimpleNode(
textLayoutResult.add(it)
}
layout != null
false
}
semanticsTextLayoutResult = localSemanticsTextLayoutResult
}
Expand Down
Expand Up @@ -16,17 +16,11 @@

package androidx.compose.ui.platform

import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.height
import androidx.compose.material.Button
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.material.Tab
import androidx.compose.material.TabRow
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.assertThat
import androidx.compose.ui.isEqualTo
Expand All @@ -36,7 +30,7 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.unit.dp
import java.awt.Point
import javax.accessibility.AccessibleRole
import javax.accessibility.AccessibleText
import kotlin.test.fail
Expand Down Expand Up @@ -74,6 +68,9 @@ class AccessibilityTest {
assertEquals("d", accessibleText.getBeforeIndex(AccessibleText.CHARACTER, 21))
assertEquals("world", accessibleText.getBeforeIndex(AccessibleText.WORD, 21))
assertEquals("Hi world", accessibleText.getBeforeIndex(AccessibleText.SENTENCE, 21))

assertEquals(0, accessibleText.getIndexAtPoint(Point(0, 0)))
assertEquals("Hello world. Hi world.".length, accessibleText.getIndexAtPoint(Point(10000, 10000)))
}

@Test
Expand Down

0 comments on commit 4c147e7

Please sign in to comment.