I'm a tad late, but I should mention a really important library I wrote that changes HOW one writes editors - http://github.com/amark/monotype . Save your caret, do whatever transformation you want directly with HTML manipulation, then you restore your caret. Done, that simple - don't even bother trying to use the browser's API, because yes they are wildly unreliable in their behavior. The kicker with my library is it saves your caret (your selection) based on actual content, rather than the DOM tree, so it still is able to accurately restore it even if you completely delete and replace the DOM tree.