Permalink
Browse files

Make output of getHistory JSON-serializable again

  • Loading branch information...
marijnh committed Sep 18, 2012
1 parent af77559 commit 949bcc48445ff3deda0cb47a4280f2b76b986e29
Showing with 12 additions and 2 deletions.
  1. +12 −2 lib/codemirror.js
View
@@ -193,8 +193,18 @@ window.CodeMirror = (function() {
history.undone = histData.undone;
},
getHistory: function() {
- history.time = 0;
- return {done: history.done.concat([]), undone: history.undone.concat([])};
+ function cp(arr) {
+ for (var i = 0, nw = [], nwelt; i < arr.length; ++i) {
+ nw.push(nwelt = []);
+ for (var j = 0, elt = arr[i]; j < elt.length; ++j) {
+ var old = [], cur = elt[j];
+ nwelt.push({start: cur.start, added: cur.added, old: old});
+ for (var k = 0; k < cur.old.length; ++k) old.push(hlText(cur.old[k]));
+ }
+ }
+ return nw;
+ }
+ return {done: cp(history.done), undone: cp(history.undone)};
},
matchBrackets: operation(function(){matchBrackets(true);}),
getTokenAt: operation(function(pos) {

0 comments on commit 949bcc4

Please sign in to comment.