Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix diacritics input in BTF2 on macOS via long-press #1810

Merged
merged 1 commit into from
Jan 30, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import java.awt.im.InputMethodRequests
import java.text.AttributedCharacterIterator
import java.text.AttributedString
import java.text.CharacterIterator
import java.util.Locale
import kotlin.math.max
import kotlin.math.min
import org.jetbrains.skiko.OS
import org.jetbrains.skiko.hostOs

internal class DesktopTextInputService(private val component: PlatformComponent) :
PlatformTextInputService {
Expand Down Expand Up @@ -116,7 +117,7 @@ internal class DesktopTextInputService(private val component: PlatformComponent)
val composing = event.text?.toStringFrom(event.committedCharacterCount).orEmpty()
val ops = mutableListOf<EditCommand>()

if (needToDeletePreviousChar && isMac && input.value.selection.min > 0 && composing.isEmpty()) {
if (needToDeletePreviousChar && input.value.selection.min > 0 && composing.isEmpty()) {
needToDeletePreviousChar = false
ops.add(DeleteSurroundingTextInCodePointsCommand(1, 0))
}
Expand Down Expand Up @@ -166,7 +167,7 @@ internal class DesktopTextInputService(private val component: PlatformComponent)
override fun getSelectedText(
attributes: Array<AttributedCharacterIterator.Attribute>?
): AttributedCharacterIterator {
if (charKeyPressed) {
if (charKeyPressed && (hostOs == OS.MacOS)) {
needToDeletePreviousChar = true
}
val str = input.value.text.substring(input.value.selection)
Expand Down Expand Up @@ -235,6 +236,3 @@ private fun AttributedCharacterIterator.toStringFrom(index: Int): String {
}
return String(strBuf)
}

private val isMac =
System.getProperty("os.name").lowercase(Locale.ENGLISH).startsWith("mac")
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import androidx.compose.ui.platform.a11y.AccessibilityController
import androidx.compose.ui.platform.a11y.ComposeSceneAccessible
import androidx.compose.ui.scene.skia.SkiaLayerComponent
import androidx.compose.ui.semantics.SemanticsOwner
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection
Expand Down Expand Up @@ -785,6 +786,11 @@ internal class ComposeSceneMediator(
})
}

@ExperimentalComposeUiApi
override fun updateSelectionState(newState: TextFieldValue) {
textInputService.updateState(oldValue = null, newValue = newState)
}

@ExperimentalComposeUiApi
override fun notifyFocusedRect(rect: Rect) {
textInputService.notifyFocusedRect(rect)
Expand Down