Why do you use `cursor`, can't you just use `selectionEnd`?