         }
         
         let indent: String = {
-            guard let baseIndentRange = indentRange.intersection(NSRange(location: 0, length: self.selectedRange.location)) else {
+            guard let baseIndentRange = indentRange.intersection(NSRange(0..<self.selectedRange.location)) else {
                 return ""
             }
-            return (string as NSString).substring(with: baseIndentRange)
+            return (self.string as NSString).substring(with: baseIndentRange)
         }()
         
         // calculation for smart indent

    
    var isAutomaticTabExpansionEnabled = false
    
    var lineHighlightRect: NSRect?
    
    var inlineCommentDelimiter: String?
    var blockCommentDelimiters: Pair<String>?
    
    var completionInitialSet = CharacterSet()  // set of the first characters of the completion words
    var needsRecompletion = false
    
    // for Scaling extension
    var initialMagnificationScale: CGFloat = 0

            return super.insertNewline(sender)
        }
        
        let indentRange = self.string.rangeOfIndent(at: self.selectedRange.location)
        
        // don't auto-indent if indent is selected (2008-12-13)
        guard indentRange.length == 0 || indentRange != self.selectedRange else {
