File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11import UIKit
22import 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 ) {
You can’t perform that action at this time.
0 commit comments