codemirror / CodeMirror-v1

An editable-iframe based code editor in JavaScript. See https://github.com/marijnh/CodeMirror for the currently maintained version
http://codemirror.net/
Other
362 stars 63 forks source link

setValue() clears undo history #58

Closed claviska closed 13 years ago

claviska commented 13 years ago

When calling setValue() the undo history gets cleared. A real-world example of when this would be undesirable is as follows:

  1. User loads CodeMirror-enabled page to edit something
  2. User makes a few changes to the source
  3. User clicks on a "Cleanup" button that sends an AJAX request to Tidy, BeautifyJS, or something similar.
  4. Source gets updated programmatically (using setValue) and undo history is cleared
  5. User wishes to undo his changes

This is one of the ways I'm using CodeMirror 2, which is why I've come across this issue. I think the following may be a feasible solution:

  1. Don't clear the undo history on setValue()
  2. Add a reset method to clear the undo/redo levels programmatically

What are your thoughts on this, Marijn?

marijnh commented 13 years ago

This was implemented in 1. Incidentally, you opened the bug on the wrong repository.