Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copy paste #1193

Merged
merged 2 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Aztec/Classes/TextKit/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we're doing this one. Why not use setItems(_:options:) in both cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that, but setItems will reset everything, so unless you first copy what you already have there and add the extra UTI to it.

} else {
pasteboard.addItems([[NSAttributedString.pastesboardUTI: data]])
}
}

// MARK: - Intercept keyboard operations
Expand Down
11 changes: 11 additions & 0 deletions AztecTests/TextKit/TextViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2016,4 +2016,15 @@ class TextViewTests: XCTestCase {

XCTAssertEqual(output, expected)
}

// MARK: - Copy tests

func testCopyAndPasteToPlainText() {
let sourceTextView = TextViewStub(withHTML: "This is text with attributes: <strong>bold</strong>")

sourceTextView.selectedRange = NSRange(location: 0, length: sourceTextView.text.count)
sourceTextView.copy(nil)

XCTAssertEqual(UIPasteboard.general.string, "This is text with attributes: bold")
}
}