 		guard let parent = codeOutlineView.parent(forItem: template) as? CodeTemplateCategory,
 				let index = Optional.some(codeOutlineView.childIndex(forItem: template)), index != -1
 			else { Log.error("", .app); return }
+//		let index = parent.childIndex(forItem: template)
 		parent.templates.value.remove(at: index)
 		codeOutlineView.removeItems(at: IndexSet(integer: index), inParent: parent, withAnimation: .slideUp)
 	}

// MARK: - main controller
class TemplatesPrefsController: NSViewController {
	let templatePasteboardType = NSPasteboard.PasteboardType(rawValue: "io.rc2.client.codeTemplate")

	// MARK: properties
	@IBOutlet private var splitterView: NSSplitView!
	@IBOutlet private var markdownButton: NSButton!

		// wrapper is not identical object
		guard let wrapperData = info.draggingPasteboard().data(forType: templatePasteboardType),
			let wrapper = try? JSONDecoder().decode(DragData.self, from: wrapperData)
			else { print("asked to acceptDrop invalid drag data"); return false }
//		let srcIndex = outlineView.childIndex(forItem: wrapper.item)
//		let targetObj = parentItem as? CodeTemplateCategory
		let fromPath = wrapper.indexPath
		let isCopy = info.draggingSourceOperationMask() == .copy
		
		var op = "move"
		if isCopy { op = "copy" }
		let out = op + " from \(fromPath), to \(index), parent: " + String(describing: parentItem)
		if last != out { print(out) }
		last = out
		
		// If we're dragging a Category:
		if wrapper.isCategory {
			let fromIndex = fromPath[0]
			// print("dropping on \(targetObj?.description ?? "nil") idx \(index) from \(wrapper.indexPath)")
			var toIndex = (index == -1) ? 0 : index	// currentCategories.count - 1
			if toIndex > fromIndex { toIndex -= 1 }
			if toIndex >= currentCategories.count { toIndex -= 1 }
//			print("from \(fromIndex), to \(toIndex)")
			if isCopy {
				//>>> TEST:
				let newCat = CodeTemplateCategory(wrapper.category!)
				currentCategories.insert(newCat, at: toIndex)
				codeOutlineView.insertItems(at: IndexSet(integer: toIndex), inParent: nil, withAnimation: .effectGap)
			} else {
				//currentCategories.moveElement(from: fromIndex, to: toIndex)
				let item = currentCategories.remove(at: fromIndex)
				currentCategories.insert(item, at: toIndex)
				if toIndex >= currentCategories.count { toIndex -= 1 }
				codeOutlineView.moveItem(at: fromIndex, inParent: nil, to: toIndex, inParent: nil)
			}
			return true
		}
		// If we're dragging a Template:
		if let toCat = parentItem as? CodeTemplateCategory, fromPath.count == 2,
			let item = wrapper.item as? CodeTemplate {
			// let fromCat = outlineView.parent(forItem: item) as! CodeTemplateCategory
			// let fromCat = codeOutlineView.parent(forItem: item) as! CodeTemplateCategory
			let fromCat = currentCategories[fromPath[0]]
			let fromIndex = fromPath[1]
			var toIndex = (index == -1) ? 0 : index // toCat.templates.value.count-1
			if toCat == fromCat {
				if toIndex > fromIndex { toIndex -= 1 }
			}
//			let toCatIndex = outlineView.childIndex(forItem: toCat)
//			print("item \(item) to \(toIndex) in \(toCat)")
			if !isCopy {
				fromCat.templates.value.remove(at: fromIndex)
				codeOutlineView.removeItems(at: IndexSet(integer: fromIndex), inParent: fromCat)
			}
			self.insert(template: item, in: toCat, at: toIndex)
			return true
		}
		return false
