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

        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]

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