Implement/caret end

moved the contentEditable == true into the method and reused variable in all subsequent places