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

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

        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)
