             // Check that the length of the entered text is shorter than the length of the suggestion.
             // This ensures that completionActive is true only if there are remaining characters to
             // suggest (which will suppress the caret).
-            if suggestion.startsWith(normalizedEnteredText) && normalizedEnteredText.characters.count < suggestion.characters.count {
-                let endingString = suggestion.substringFromIndex(suggestion.startIndex.advancedBy(normalizedEnteredText.characters.count))
+            if suggestion.startsWith(normalizeString(enteredText)) && normalizeString(enteredText).characters.count < suggestion.characters.count {
+                let endingString = suggestion.substringFromIndex(suggestion.startIndex.advancedBy(normalizeString(enteredText).characters.count))
                 let completedAndMarkedString = NSMutableAttributedString(string: enteredText + endingString)
                 completedAndMarkedString.addAttribute(NSBackgroundColorAttributeName, value: highlightColor, range: NSMakeRange(enteredText.characters.count, endingString.characters.count))
                 attributedText = completedAndMarkedString

        selectedTextRange = textRangeFromPosition(beginningOfDocument, toPosition: beginningOfDocument)
    }

    /// Commits the completion by setting the text and removing the highlight.
    private func applyCompletion() {
        if completionActive {


    private func removeCompletionIfRequiredForEnteredString(string: String) {
        // If user-entered text does not start with previous suggestion then remove the completion.

        let actualEnteredString = enteredText + string
        // Detecting the keyboard type, and remove hightlight in "zh-Hans" and "ja-JP"
        if !previousSuggestion.startsWith(normalizeString(actualEnteredString)) ||
            UIApplication.sharedApplication().textInputMode?.primaryLanguage == "zh-Hans" ||
            UIApplication.sharedApplication().textInputMode?.primaryLanguage == "ja-JP" {
            removeCompletion()
        }
        enteredText = actualEnteredString
