 	private var openDocuments:[Int:EditorDocument] = [:]
 	private var defaultAttributes:[String:AnyObject]! //set in viewDidLoad, never used unless loaded
 	private var currentChunkIndex = 0
+	
+	///true when we should ignore text storage delegate callbacks, such as when deleting the text prior to switching documents
+	private var ignoreTextStorageNotifications = false
 	
 	private var myFontDescriptor:NSFontDescriptor?
 	

				openDocuments[theFile.fileId] = currentDocument!
			}
			currentDocument!.willBecomeActive()
			storage.deleteCharactersInRange(editor!.rangeOfAllText)
			parser = SyntaxParser.parserWithTextStorage(storage, fileType: theFile.fileType)
			storage.setAttributedString(NSAttributedString(string: theText, attributes: defaultAttributes))
			if oldDocument?.dirty ?? false {
				let prog = oldDocument!.saveContents()

	//called when text editing has ended
	func textStorage(textStorage: NSTextStorage, didProcessEditing editedMask: NSTextStorageEditActions, range editedRange: NSRange, changeInLength delta: Int)
	{
		guard !ignoreTextStorageNotifications else { return }
		//we don't care if attributes changed
		guard editedMask.contains(.EditedCharacters) else { return }
		guard parser != nil else { return }
