refactor textarea document manipulation into one place