Refactor the Ghost Editor

issue #2385, issue #2108

- Separate out the various objects which form the editor into their own
  modules
- Decouple the modules where possible
- Rename and reshuffle bits of modules for consistency
- Minimise public APIs of the modules, and ensure they are consistent
- Add comments to the modules
Upgrade CodeMirror

closes #2108

- upgrade to 4.0.1
- requires removing the deprecated setLine method
Fix undo bug

issue #2398#issuecomment-37761224
Mobile commit