Tree: Adopt children properly when moving a node to another tree. Fixes #1689.

See #1689 for a description of the issue.