kopia lustrzana https://github.com/c9/core
fix save test
rodzic
873143a725
commit
8312d3d5ac
|
@ -297,12 +297,15 @@ define(function(require, exports, module) {
|
|||
undoManager.canRedo = this.canRedo;
|
||||
undoManager.getState = this.getState;
|
||||
undoManager.setState = this.setState;
|
||||
undoManager.bookmark = this.bookmark;
|
||||
undoManager.bookmark = this.bookmarkPosition;
|
||||
undoManager.isAtBookmark = this.isAtBookmark;
|
||||
undoManager.__defineGetter__("position", this.getPosition);
|
||||
undoManager.__defineGetter__("length", this.getLength);
|
||||
undoManager._emit = this._emit = undoManager.getEmitter();
|
||||
|
||||
this.deleyedEmit = lang.delayedCall(this._emit.bind(null, "change"))
|
||||
.schedule.bind(null, 0);
|
||||
undoManager.on("changeSync", this.deleyedEmit);
|
||||
this.setState(state);
|
||||
}
|
||||
function updateDeltas(deltas) {
|
||||
|
@ -318,22 +321,22 @@ define(function(require, exports, module) {
|
|||
AceUndoManager.prototype = {
|
||||
add: function(delta, doc) {
|
||||
this.$aceUndo.add(delta, doc);
|
||||
this._emit("change");
|
||||
this._emit("changeSync");
|
||||
},
|
||||
addSelection: function(range, rev) {
|
||||
this.$aceUndo.addSelection(range, rev);
|
||||
},
|
||||
undo: function(dontSelect) {
|
||||
this.$aceUndo.undo(dontSelect);
|
||||
this._emit("change");
|
||||
this._emit("changeSync");
|
||||
},
|
||||
redo: function(dontSelect) {
|
||||
this.$aceUndo.redo(dontSelect);
|
||||
this._emit("change");
|
||||
this._emit("changeSync");
|
||||
},
|
||||
reset: function(){
|
||||
this.$aceUndo.reset();
|
||||
this._emit("change");
|
||||
this._emit("changeSync");
|
||||
},
|
||||
canUndo: function() {
|
||||
return this.$aceUndo.canUndo();
|
||||
|
@ -343,11 +346,11 @@ define(function(require, exports, module) {
|
|||
},
|
||||
clearUndo: function() {
|
||||
this.$aceUndo.$undoStack = [];
|
||||
this._emit("change");
|
||||
this._emit("changeSync");
|
||||
},
|
||||
clearRedo: function() {
|
||||
this.$aceUndo.$redoStack = [];
|
||||
this._emit("change");
|
||||
this._emit("changeSync");
|
||||
},
|
||||
getState: function() {
|
||||
console.log("getState()");
|
||||
|
@ -379,9 +382,27 @@ define(function(require, exports, module) {
|
|||
isAtBookmark: function() {
|
||||
return this.$aceUndo.isAtBookmark();
|
||||
},
|
||||
bookmark: function(index) {
|
||||
this.$aceUndo.bookmark(index);
|
||||
this._emit("change");
|
||||
bookmark: function(rev) {
|
||||
this.$aceUndo.bookmark(rev);
|
||||
this._emit("changeSync");
|
||||
},
|
||||
bookmarkPosition: function(index) {
|
||||
if (index > -1) {
|
||||
var stack = this.$aceUndo.$undoStack;
|
||||
if (index >= stack.length) {
|
||||
index -= stack.length;
|
||||
stack = this.$aceUndo.$redoStack;
|
||||
index = stack.length - index;
|
||||
}
|
||||
var deltaSet = stack[index];
|
||||
var rev = deltaSet && deltaSet[0] && deltaSet[0].id;
|
||||
this.$aceUndo.bookmark(rev);
|
||||
} else if (index == -1) {
|
||||
this.$aceUndo.bookmark(0);
|
||||
} else {
|
||||
this.$aceUndo.bookmark(index);
|
||||
}
|
||||
this._emit("changeSync");
|
||||
},
|
||||
setSession: function(session) {
|
||||
this.$aceUndo.setSession(session);
|
||||
|
@ -390,6 +411,10 @@ define(function(require, exports, module) {
|
|||
var aceUndo = this.$aceUndo;
|
||||
return aceUndo.$undoStack.length - 1;
|
||||
},
|
||||
getMark: function() {
|
||||
var aceUndo = this.$aceUndo;
|
||||
return aceUndo.$undoStack.length - 1;
|
||||
},
|
||||
getLength: function() {
|
||||
var aceUndo = this.$aceUndo;
|
||||
return aceUndo.$undoStack.length + aceUndo.$redoStack.length;
|
||||
|
|
|
@ -40,16 +40,15 @@ define(function(require, module, exports) {
|
|||
|
||||
// Listen to changes and detect when the value of the editor
|
||||
// is different from what is on disk
|
||||
function initUndo(){
|
||||
undoManager.on("change", function(e) {
|
||||
var c = !undoManager.isAtBookmark();
|
||||
if (changed !== c || undoManager.position == -1) {
|
||||
changed = c;
|
||||
emit("changed", { changed: c });
|
||||
}
|
||||
});
|
||||
function updateStatus(e) {
|
||||
var c = !undoManager.isAtBookmark();
|
||||
if (changed !== c) {
|
||||
changed = c;
|
||||
emit("changed", { changed: c });
|
||||
}
|
||||
}
|
||||
initUndo();
|
||||
undoManager.on("change", updateStatus);
|
||||
undoManager.on("changeSync", updateStatus);
|
||||
|
||||
/***** Methods *****/
|
||||
|
||||
|
@ -60,26 +59,24 @@ define(function(require, module, exports) {
|
|||
}
|
||||
var state = getState();
|
||||
|
||||
undoManager.once("change", function(){
|
||||
// Bookmark the undo manager
|
||||
undoManager.bookmark();
|
||||
|
||||
// Update state
|
||||
delete state.changed;
|
||||
delete state.value;
|
||||
delete state.meta;
|
||||
state.undoManager = undoManager.getState();
|
||||
|
||||
if (cleansed && editor && state[editor.type])
|
||||
state[editor.type].cleansed = true;
|
||||
|
||||
// Set new state (preserving original state)
|
||||
if (emit("mergeState") !== false)
|
||||
setState(state);
|
||||
});
|
||||
|
||||
// Record value (which should add an undo stack item)
|
||||
plugin.value = value;
|
||||
|
||||
// Bookmark the undo manager
|
||||
undoManager.bookmark();
|
||||
|
||||
// Update state
|
||||
delete state.changed;
|
||||
delete state.value;
|
||||
delete state.meta;
|
||||
state.undoManager = undoManager.getState();
|
||||
|
||||
if (cleansed && editor && state[editor.type])
|
||||
state[editor.type].cleansed = true;
|
||||
|
||||
// Set new state (preserving original state)
|
||||
if (emit("mergeState") !== false)
|
||||
setState(state);
|
||||
}
|
||||
|
||||
function getState(filter) {
|
||||
|
|
|
@ -309,11 +309,8 @@ define(function(require, exports, module) {
|
|||
doc.meta.$mergeRoot = data;
|
||||
|
||||
// If the value on disk is the same as in the document, set the bookmark
|
||||
if (mergedValue == data) {
|
||||
doc.undoManager.once("change", function(){
|
||||
doc.undoManager.bookmark();
|
||||
});
|
||||
}
|
||||
if (mergedValue == data)
|
||||
doc.undoManager.bookmark();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue