         let string = self.string
         var selections = [NSAttributedString]()
         var propertyList = [Int]()
-        let lineEnding = self.documentLineEnding ?? .LF
+        let lineEnding = self.document?.lineEnding ?? .LF
         
         // substring all selected attributed strings
         let selectedRanges = self.selectedRanges as! [NSRange]

        
        let success = super.writeSelection(to: pboard, types: types)
        
        guard let lineEnding = self.documentLineEnding, lineEnding == .LF else { return success }
        
        for type in types {
            guard let string = pboard.string(forType: type) else { continue }

        var selectedString = (self.string as NSString).substring(with: self.selectedRange)
        
        // apply document's line ending
        if let documentLineEnding = self.document?.lineEnding,
            documentLineEnding != .LF, selectedString.detectedLineEnding == .LF
        {
            selectedString = selectedString.replacingLineEndings(with: documentLineEnding)
