diff --git a/ios/engine/KMEI/KeymanEngine/Classes/InputViewController.swift b/ios/engine/KMEI/KeymanEngine/Classes/InputViewController.swift index 35cabcb4b3..f33b478ab3 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/InputViewController.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/InputViewController.swift @@ -371,13 +371,18 @@ open class InputViewController: UIInputViewController, KeymanWebDelegate { textDocumentProxy.deleteBackward() let newContext = textDocumentProxy.documentContextBeforeInput ?? "" let unitsDeleted = oldContext.utf16.count - newContext.utf16.count - if unitsDeleted > 1 { - if !InputViewController.isSurrogate(oldContext.utf16.last!) { - let lowerIndex = oldContext.utf16.index(oldContext.utf16.startIndex, - offsetBy: newContext.utf16.count) - let upperIndex = oldContext.utf16.index(lowerIndex, offsetBy: unitsDeleted - 1) - textDocumentProxy.insertText(String(oldContext[lowerIndex.. unitsInPoint { + // Delete only that many units. + let lowerIndex = oldContext.utf16.index(oldContext.utf16.startIndex, + offsetBy: newContext.utf16.count) + let upperIndex = oldContext.utf16.index(lowerIndex, offsetBy: unitsDeleted - unitsInPoint) + textDocumentProxy.insertText(String(oldContext[lowerIndex..