Skip to content

Commit 5367dbf

Browse files
Merge pull request #1196 from wordpress-mobile/release/1.6.6
Release 1.6.6
2 parents acc82a9 + e993e6f commit 5367dbf

5 files changed

Lines changed: 48 additions & 4 deletions

File tree

Aztec/Classes/TextKit/TextStorage.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ open class TextStorage: NSTextStorage {
365365
open func getHTML(prettify: Bool = false) -> String {
366366
return htmlConverter.html(from: self, prettify: prettify)
367367
}
368+
369+
open func getHTML(prettify: Bool = false, range: NSRange) -> String {
370+
return htmlConverter.html(from: self.attributedSubstring(from: range), prettify: prettify)
371+
}
368372

369373
func setHTML(_ html: String, defaultAttributes: [NSAttributedString.Key: Any]) {
370374
let originalLength = length

Aztec/Classes/TextKit/TextView.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import UIKit
22
import Foundation
3-
3+
import CoreServices
44

55
// MARK: - TextViewAttachmentDelegate
66
//
@@ -458,16 +458,20 @@ open class TextView: UITextView {
458458

459459
open override func cut(_ sender: Any?) {
460460
let data = storage.attributedSubstring(from: selectedRange).archivedData()
461+
let html = storage.getHTML(range: selectedRange)
461462
super.cut(sender)
462463

463464
storeInPasteboard(encoded: data)
465+
storeInPasteboard(html: html)
464466
}
465467

466468
open override func copy(_ sender: Any?) {
467469
let data = storage.attributedSubstring(from: selectedRange).archivedData()
470+
let html = storage.getHTML(range: selectedRange)
468471
super.copy(sender)
469472

470473
storeInPasteboard(encoded: data)
474+
storeInPasteboard(html: html)
471475
}
472476

473477
open override func paste(_ sender: Any?) {
@@ -562,6 +566,14 @@ open class TextView: UITextView {
562566
}
563567
}
564568

569+
internal func storeInPasteboard(html: String, pasteboard: UIPasteboard = UIPasteboard.general) {
570+
if pasteboard.numberOfItems > 0 {
571+
pasteboard.items[0][kUTTypeHTML as String] = html;
572+
} else {
573+
pasteboard.addItems([[kUTTypeHTML as String: html]])
574+
}
575+
}
576+
565577
// MARK: - Intercept keyboard operations
566578

567579
open override func insertText(_ text: String) {

AztecTests/TextKit/TextViewTests.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2017,7 +2017,7 @@ class TextViewTests: XCTestCase {
20172017
XCTAssertEqual(output, expected)
20182018
}
20192019

2020-
// MARK: - Copy tests
2020+
// MARK: - Copy/Paste tests
20212021

20222022
func testCopyAndPasteToPlainText() {
20232023
let sourceTextView = TextViewStub(withHTML: "This is text with attributes: <strong>bold</strong>")
@@ -2027,4 +2027,32 @@ class TextViewTests: XCTestCase {
20272027

20282028
XCTAssertEqual(UIPasteboard.general.string, "This is text with attributes: bold")
20292029
}
2030+
2031+
func testCopyHTML() {
2032+
let sourceTextView = TextViewStub(withHTML: "<p>This is text with attributes: <strong>bold</strong> and <italic>italic</italic></p>")
2033+
2034+
sourceTextView.selectedRange = NSRange(location: 0, length: sourceTextView.text.count)
2035+
sourceTextView.copy(nil)
2036+
2037+
XCTAssertEqual(UIPasteboard.general.html(), "<p>This is text with attributes: <strong>bold</strong> and <italic>italic</italic></p>")
2038+
}
2039+
2040+
func testCutHTML() {
2041+
let sourceTextView = TextViewStub(withHTML: "<p>This is text with attributes: <strong>bold</strong> and <italic>italic</italic></p>")
2042+
2043+
sourceTextView.selectedRange = NSRange(location: 0, length: sourceTextView.text.count)
2044+
sourceTextView.cut(nil)
2045+
2046+
XCTAssertEqual(UIPasteboard.general.html(), "<p>This is text with attributes: <strong>bold</strong> and <italic>italic</italic></p>")
2047+
}
2048+
2049+
func testCopyPartialHTML() {
2050+
let sourceTextView = TextViewStub(withHTML: "<p><strong>bold</strong> and <italic>italic</italic></p>")
2051+
2052+
sourceTextView.selectedRange = NSRange(location: 0, length: 3)
2053+
sourceTextView.copy(nil)
2054+
2055+
XCTAssertEqual(UIPasteboard.general.html(), "<p><strong>bol</strong></p>")
2056+
}
2057+
20302058
}

WordPress-Aztec-iOS.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'WordPress-Aztec-iOS'
11-
s.version = '1.6.5'
11+
s.version = '1.6.6'
1212
s.summary = 'The native HTML Editor.'
1313

1414
# This description is used to generate tags and improve search results.

WordPress-Editor-iOS.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'WordPress-Editor-iOS'
11-
s.version = '1.6.5'
11+
s.version = '1.6.6'
1212
s.summary = 'The WordPress HTML Editor.'
1313

1414
# This description is used to generate tags and improve search results.

0 commit comments

Comments
 (0)