diff --git a/Aztec/Classes/Formatters/Implementations/HeaderFormatter.swift b/Aztec/Classes/Formatters/Implementations/HeaderFormatter.swift index 176cfb17e..3d458020a 100644 --- a/Aztec/Classes/Formatters/Implementations/HeaderFormatter.swift +++ b/Aztec/Classes/Formatters/Implementations/HeaderFormatter.swift @@ -42,12 +42,15 @@ open class HeaderFormatter: ParagraphAttributeFormatter { } else { newParagraphStyle.replaceProperty(ofType: Header.self, with: header) } - - let targetFontSize = headerFontSize(for: headerLevel, defaultSize: defaultSize) + + let targetFontSize = CGFloat(headerFontSize(for: headerLevel, defaultSize: defaultSize)) var resultingAttributes = attributes + + let newDescriptor = font.fontDescriptor.addingAttributes([.size: targetFontSize]) + resultingAttributes[.paragraphStyle] = newParagraphStyle - resultingAttributes[.font] = font.withSize(CGFloat(targetFontSize)) - + resultingAttributes[.font] = UIFont(descriptor: newDescriptor, size: targetFontSize) + return resultingAttributes } diff --git a/Aztec/Classes/TextKit/TextStorage.swift b/Aztec/Classes/TextKit/TextStorage.swift index 2596bfda0..d51244589 100644 --- a/Aztec/Classes/TextKit/TextStorage.swift +++ b/Aztec/Classes/TextKit/TextStorage.swift @@ -267,9 +267,6 @@ open class TextStorage: NSTextStorage { edited([.editedAttributes, .editedCharacters], range: range, changeInLength: attrString.length - range.length) - let invalidateRange = NSMakeRange(range.location, attrString.length) - invalidateAttributes(in: invalidateRange) - endEditing() } @@ -408,7 +405,7 @@ private extension TextStorage { guard oldLevel != newLevel else { return attrs } - + return fixFontAttribute(in: attrs, headerLevel: newLevel) } diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index 4cedcffc5..44e31ea5e 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -248,7 +248,6 @@ open class TextView: UITextView { } } - /// Returns the collection of Typing Attributes, with all of the available 'String' keys properly converted into /// NSAttributedStringKey. Also known as: what you would expect from the SDK. /// @@ -599,6 +598,20 @@ open class TextView: UITextView { return caretRect } + + /// When typing with the Chinese keyboard, the text is automatically marked in the editor. + /// You have to press ENTER once to confirm your chosen input. The problem is that in iOS 11 + /// the typing attributes are lost when the text is unmarked, causing the font to be lost. + /// Since localized characters need specific fonts to be rendered, this causes some characters + /// to stop rendering completely. + /// + /// Reference: https://github.com/wordpress-mobile/AztecEditor-iOS/issues/811 + /// + override open func unmarkText() { + preserveTypingAttributesForInsertion { + super.unmarkText() + } + } // MARK: - HTML Interaction