Use style.setProperty to avoid problems on older Gecko versions
Handle newlines in div with '\n' characters; add a trailing '\n' to the div to avoid newline rendering issues; take the additional '\n' into account when getting or setting the caret position