From 78a12b1c9a788a898d16d3d8941ade6f7daaf087 Mon Sep 17 00:00:00 2001 From: Yozone Wang Date: Tue, 24 Oct 2017 15:35:49 +0800 Subject: [PATCH 1/5] Fix keyboard auto-correction crash issue(if the view is inherited from TextView) --- Aztec/Classes/TextKit/TextView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index b0e28566a..2bcb3e410 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -1013,7 +1013,7 @@ open class TextView: UITextView { // From here on, it's just calling the same method in `super`. // let selector = #selector(TextView.replaceRangeWithTextWithoutClosingTyping(_:replacementText:)) - let imp = class_getMethodImplementation(self.superclass, selector) + let imp = class_getMethodImplementation(TextView.superclass(), selector) typealias ClosureType = @convention(c) (AnyObject, Selector, UITextRange, String) -> Void let superMethod: ClosureType = unsafeBitCast(imp, to: ClosureType.self) From fbc6279837fc2b38bd349f798458082402482538 Mon Sep 17 00:00:00 2001 From: Yozone Wang Date: Mon, 30 Oct 2017 14:58:58 +0800 Subject: [PATCH 2/5] TextStorage: Fixed large text crash issue(#791) --- Aztec/Classes/TextKit/TextStorage.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Aztec/Classes/TextKit/TextStorage.swift b/Aztec/Classes/TextKit/TextStorage.swift index bd5c7885e..81c966954 100644 --- a/Aztec/Classes/TextKit/TextStorage.swift +++ b/Aztec/Classes/TextKit/TextStorage.swift @@ -83,6 +83,8 @@ open class TextStorage: NSTextStorage { fileprivate var textStore = NSMutableAttributedString(string: "", attributes: nil) + fileprivate var textStoreString = "" + // MARK: - Delegates @@ -99,7 +101,7 @@ open class TextStorage: NSTextStorage { // MARK: - Calculated Properties override open var string: String { - return textStore.string + return textStoreString } open var mediaAttachments: [MediaAttachment] { @@ -239,6 +241,11 @@ open class TextStorage: NSTextStorage { detectAttachmentRemoved(in: range) textStore.replaceCharacters(in: range, with: str) + let utf16String = textStoreString.utf16 + let startIndex = utf16String.index(utf16String.startIndex, offsetBy: range.location) + let endIndex = utf16String.index(startIndex, offsetBy: range.length) + textStoreString.replaceSubrange(startIndex.. Date: Mon, 30 Oct 2017 15:17:33 +0800 Subject: [PATCH 3/5] Extract replaceTextStoreString method --- Aztec/Classes/TextKit/TextStorage.swift | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Aztec/Classes/TextKit/TextStorage.swift b/Aztec/Classes/TextKit/TextStorage.swift index 81c966954..25b4a28db 100644 --- a/Aztec/Classes/TextKit/TextStorage.swift +++ b/Aztec/Classes/TextKit/TextStorage.swift @@ -233,6 +233,13 @@ open class TextStorage: NSTextStorage { return textStore.attributes(at: location, effectiveRange: range) } + + private func replaceTextStoreString(_ range: NSRange, with string: String) { + let utf16String = textStoreString.utf16 + let startIndex = utf16String.index(utf16String.startIndex, offsetBy: range.location) + let endIndex = utf16String.index(startIndex, offsetBy: range.length) + textStoreString.replaceSubrange(startIndex.. Date: Tue, 31 Oct 2017 10:50:56 +0800 Subject: [PATCH 4/5] Revert "Extract replaceTextStoreString method" This reverts commit 7139f5f2fd6df7f3dbb6b001eeb393ca0427b07b. --- Aztec/Classes/TextKit/TextStorage.swift | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Aztec/Classes/TextKit/TextStorage.swift b/Aztec/Classes/TextKit/TextStorage.swift index 25b4a28db..81c966954 100644 --- a/Aztec/Classes/TextKit/TextStorage.swift +++ b/Aztec/Classes/TextKit/TextStorage.swift @@ -233,13 +233,6 @@ open class TextStorage: NSTextStorage { return textStore.attributes(at: location, effectiveRange: range) } - - private func replaceTextStoreString(_ range: NSRange, with string: String) { - let utf16String = textStoreString.utf16 - let startIndex = utf16String.index(utf16String.startIndex, offsetBy: range.location) - let endIndex = utf16String.index(startIndex, offsetBy: range.length) - textStoreString.replaceSubrange(startIndex.. Date: Tue, 31 Oct 2017 10:51:07 +0800 Subject: [PATCH 5/5] Revert "TextStorage: Fixed large text crash issue(#791)" This reverts commit fbc6279837fc2b38bd349f798458082402482538. --- Aztec/Classes/TextKit/TextStorage.swift | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/Aztec/Classes/TextKit/TextStorage.swift b/Aztec/Classes/TextKit/TextStorage.swift index 81c966954..bd5c7885e 100644 --- a/Aztec/Classes/TextKit/TextStorage.swift +++ b/Aztec/Classes/TextKit/TextStorage.swift @@ -83,8 +83,6 @@ open class TextStorage: NSTextStorage { fileprivate var textStore = NSMutableAttributedString(string: "", attributes: nil) - fileprivate var textStoreString = "" - // MARK: - Delegates @@ -101,7 +99,7 @@ open class TextStorage: NSTextStorage { // MARK: - Calculated Properties override open var string: String { - return textStoreString + return textStore.string } open var mediaAttachments: [MediaAttachment] { @@ -241,11 +239,6 @@ open class TextStorage: NSTextStorage { detectAttachmentRemoved(in: range) textStore.replaceCharacters(in: range, with: str) - let utf16String = textStoreString.utf16 - let startIndex = utf16String.index(utf16String.startIndex, offsetBy: range.location) - let endIndex = utf16String.index(startIndex, offsetBy: range.length) - textStoreString.replaceSubrange(startIndex..