What is problem here?
if ( window.getSelection() )
EditField = window.getSelection().getRangeAt(0);
throws error:
<
Here is something to consider: have you disabled selection somewhere in your code? If so, in some situations you may want to first enable selection, preferably in a mousedown event or before focusing on your element (NB!), before getting the range. Doing this has solved my version of the problem.
$('#MyEditableDiv').on('mousedown', function (e) {
$(document).enableSelection();
});