Probably better to make this a parsed expression, and update it when it changes. It might not necessarily be good to add another watch, but I'm not sure it's sensible to build this each time a node is dropped.

Also, I think the previous comment I mentioned about crawling up the tree if the current node isn't droppable makes sense, crawling up should typically not hurt performance very much and typically only be a few loops.

Shouldn't even bother trying to drop over text nodes, so if the dropped element's type is 3, just skip right to its parent. (would be a good idea to keep track of the position though so we have a good idea where to insert the node)

This patch is starting to look better but I think it needs a bit of work. Good stuff all in all though