From ecffb55d7648fd43dae958711557aaa18f44cf32 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Fri, 24 May 2019 11:25:29 +0100 Subject: [PATCH 1/2] Fix copy method to keep other text data when adding custom attributed string data. --- Aztec/Classes/TextKit/TextView.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index d30c5872d..5faf3f93d 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -555,7 +555,11 @@ open class TextView: UITextView { // MARK: - Pasteboard Helpers internal func storeInPasteboard(encoded data: Data, pasteboard: UIPasteboard = UIPasteboard.general) { - pasteboard.setData(data, forPasteboardType: NSAttributedString.pastesboardUTI) + if pasteboard.numberOfItems > 0 { + pasteboard.items[0][NSAttributedString.pastesboardUTI] = data; + } else { + pasteboard.addItems([[NSAttributedString.pastesboardUTI: data]]) + } } // MARK: - Intercept keyboard operations From 2aac8bf4ef888ecfbfff94b4a0ff610b8851f1f7 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Fri, 24 May 2019 17:47:06 +0100 Subject: [PATCH 2/2] Add unit test to detect in plain text is available when doing copy --- AztecTests/TextKit/TextViewTests.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/AztecTests/TextKit/TextViewTests.swift b/AztecTests/TextKit/TextViewTests.swift index 4cbc35b68..a5e8b5a64 100644 --- a/AztecTests/TextKit/TextViewTests.swift +++ b/AztecTests/TextKit/TextViewTests.swift @@ -2016,4 +2016,15 @@ class TextViewTests: XCTestCase { XCTAssertEqual(output, expected) } + + // MARK: - Copy tests + + func testCopyAndPasteToPlainText() { + let sourceTextView = TextViewStub(withHTML: "This is text with attributes: bold") + + sourceTextView.selectedRange = NSRange(location: 0, length: sourceTextView.text.count) + sourceTextView.copy(nil) + + XCTAssertEqual(UIPasteboard.general.string, "This is text with attributes: bold") + } }