directly replace text when formatting

Avoid multiple edit dispatching from code mirror, and add only one
change in history
Merge branch 'develop'