Probably the best way is to keep synchronized state as CodeMirror state, and uncommited changes being decorations. Or maintaining two states in CM.