         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]

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

    private var document: Document? {
        
        return self.window?.windowController?.document as? Document
    }
    
    
