fix undo manager
This commit is contained in:
parent
81a742e2f1
commit
c879e0a802
1 changed files with 29 additions and 23 deletions
|
|
@ -93,6 +93,7 @@ var EditSession = function(text, mode) {
|
|||
|
||||
this.setValue = function(text) {
|
||||
this.doc.setValue(text);
|
||||
this.$deltas = [];
|
||||
};
|
||||
|
||||
this.getValue =
|
||||
|
|
@ -479,36 +480,41 @@ var EditSession = function(text, mode) {
|
|||
};
|
||||
|
||||
this.undoChanges = function(deltas) {
|
||||
this.selection.clearSelection();
|
||||
if (!deltas.length)
|
||||
return;
|
||||
|
||||
this.$fromUndo = true;
|
||||
for (var i=deltas.length-1; i>=0; i--) {
|
||||
var delta = deltas[i];
|
||||
if (delta.action == "insertText") {
|
||||
this.remove(delta.range, true);
|
||||
this.selection.moveCursorToPosition(delta.range.start);
|
||||
} else {
|
||||
this.insert(delta.range.start, delta.text, true);
|
||||
this.selection.clearSelection();
|
||||
}
|
||||
}
|
||||
this.doc.revertDeltas(deltas);
|
||||
this.$fromUndo = false;
|
||||
|
||||
// update the selection
|
||||
var firstDelta = deltas[0];
|
||||
var lastDelta = deltas[deltas.length-1];
|
||||
|
||||
this.selection.clearSelection();
|
||||
if (firstDelta.action == "insertText" || firstDelta.action == "insertLines")
|
||||
this.selection.moveCursorToPosition(firstDelta.range.start);
|
||||
if (firstDelta.action == "removeText" || firstDelta.action == "removeLines")
|
||||
this.selection.setSelectionRange(Range.fromPoints(firstDelta.range.start, lastDelta.range.end));
|
||||
},
|
||||
|
||||
this.redoChanges = function(deltas) {
|
||||
this.selection.clearSelection();
|
||||
|
||||
if (!deltas.length)
|
||||
return;
|
||||
|
||||
this.$fromUndo = true;
|
||||
for (var i=0; i<deltas.length; i++) {
|
||||
var delta = deltas[i];
|
||||
if (delta.action == "insertText") {
|
||||
this.insert(delta.range.start, delta.text, true);
|
||||
this.selection.setSelectionRange(delta.range);
|
||||
} else {
|
||||
this.remove(delta.range, true);
|
||||
this.selection.moveCursorToPosition(delta.range.start);
|
||||
}
|
||||
}
|
||||
this.doc.applyDeltas(deltas);
|
||||
this.$fromUndo = false;
|
||||
|
||||
// update the selection
|
||||
var firstDelta = deltas[0];
|
||||
var lastDelta = deltas[deltas.length-1];
|
||||
|
||||
this.selection.clearSelection();
|
||||
if (firstDelta.action == "insertText" || firstDelta.action == "insertLines")
|
||||
this.selection.setSelectionRange(Range.fromPoints(firstDelta.range.start, lastDelta.range.end));
|
||||
if (firstDelta.action == "removeText" || firstDelta.action == "removeLines")
|
||||
this.selection.moveCursorToPosition(firstDelta.range.start);
|
||||
},
|
||||
|
||||
this.replace = function(range, text) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue