Merge pull request #2398 from ErisDS/cm-refactor

CodeMirror Refactor & Upgrade
Force preview to scroll to the end

fixes #958, fixes #535

- If the cursor is within the last 5 lines, then scroll to the end of the preview window, rather than using a ratio