From 681d5d9bbbd3cfa3e0cbbf1c9308fc29ef7c8043 Mon Sep 17 00:00:00 2001 From: jahorton Date: Wed, 21 Apr 2021 10:46:08 +0700 Subject: [PATCH] fix(ios): proper context synchronization for combo emoji deletion --- .../Classes/InputViewController.swift | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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..