[jQuery] re-establish user selection in a div with designmode=true

[jQuery] re-establish user selection in a div with designmode=true


I have a web app where I have created a div to masquerade at a
textarea so I can add highlighting according to so rules. I rely on
setting designmode=true. After certain amounts of idle time my code
grabs the text from the div, which consists of

tags and <span>
tags and re-generates the html with new spans. The paragraphs and text
stay the same. So far so good. But when the div "repaints" the
insertion is set to the beginning of the div. I want it to visually
stay put, meaning I need to somehow record where it was before and
then restore it afterwards.
Problem is, I can't seem to get my head wrapped around how selections
(Ranges, etc.) work. I've been googling around for the last day or so
and have not yet seen the light.
Any ideas?