Fix bug: can't use window.getSelection().getRangeAt(0) before addRange