Skip to content

Commit 2bfdee1

Browse files
authored
Fix RTL characters deletion (#1952)
Use `DeleteSurroundingTextCommand` when no characters was auto-selected by iOS before `deleteBackward` call. Fixes https://youtrack.jetbrains.com/issue/CMP-7174/Compose-Multiplatform-InputField-with-special-Arabic-characters-on-iOS ## Release Notes ### Fixes - iOS - _(prerelease fix)_ Fix deletion of certain RTL characters
1 parent 038ac3f commit 2bfdee1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/platform/UIKitTextInputService.uikit.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import androidx.compose.ui.scene.ComposeSceneFocusManager
2828
import androidx.compose.ui.text.TextLayoutResult
2929
import androidx.compose.ui.text.TextRange
3030
import androidx.compose.ui.text.input.CommitTextCommand
31+
import androidx.compose.ui.text.input.DeleteSurroundingTextCommand
3132
import androidx.compose.ui.text.input.EditCommand
3233
import androidx.compose.ui.text.input.EditProcessor
3334
import androidx.compose.ui.text.input.FinishComposingTextCommand
@@ -478,11 +479,13 @@ internal class UIKitTextInputService(
478479
* https://developer.apple.com/documentation/uikit/uikeyinput/1614572-deletebackward
479480
*/
480481
override fun deleteBackward() {
481-
// Before this function calls, iOS changes selection in setSelectedTextRange.
482-
// All needed characters should be already selected, and we can just remove them.
483-
sendEditCommand(
484-
CommitTextCommand("", 0)
485-
)
482+
val deleteCommand =
483+
if (_tempCurrentInputSession?.toTextFieldValue()?.selection?.collapsed == true) {
484+
DeleteSurroundingTextCommand(lengthBeforeCursor = 1, lengthAfterCursor = 0)
485+
} else {
486+
CommitTextCommand("", 0)
487+
}
488+
sendEditCommand(deleteCommand)
486489
}
487490

488491
/**

0 commit comments

Comments
 (0)