File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -16,12 +16,10 @@ public class LTXAttachment {
1616        size =  . zero
1717    } 
1818
19-     // 获取 attachment 的文本表示
2019    public  func  attributedStringRepresentation( )  ->  NSAttributedString  { 
2120        if  let  view =  view as?  LTXAttributeStringRepresentable  { 
2221            return  view. attributedStringRepresentation ( ) 
2322        } 
24-         // 如果没有实现协议,返回空格
2523        return  NSAttributedString ( string:  "   " ) 
2624    } 
2725
Original file line number Diff line number Diff line change @@ -81,9 +81,25 @@ extension LTXLabel {
8181            length:  min ( range. length,  maxLen) 
8282        ) 
8383
84-         return  textLayout
84+         let   selectedText   =  textLayout
8585            . attributedString
8686            . attributedSubstring ( from:  safeRange) 
87+ 
88+         let  mutableResult  =  NSMutableAttributedString ( attributedString:  selectedText) 
89+         mutableResult. enumerateAttribute ( 
90+             LTXAttachmentAttributeName, 
91+             in:  NSRange ( location:  0 ,  length:  mutableResult. length) , 
92+             options:  [ ] 
93+         )  {  value,  range,  _ in 
94+             if  let  attachment =  value as?  LTXAttachment  { 
95+                 mutableResult. replaceCharacters ( 
96+                     in:  range, 
97+                     with:  attachment. attributedStringRepresentation ( ) 
98+                 ) 
99+             } 
100+         } 
101+ 
102+         return  mutableResult
87103    } 
88104
89105    func  selectedPlainText( )  ->  String ? { 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments