I had to do something similar a while ago to implement drag&drop while keeping text selectable.
Reply on news.ycombinator.com