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.setValue = function(text) {
|
||||||
this.doc.setValue(text);
|
this.doc.setValue(text);
|
||||||
|
this.$deltas = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getValue =
|
this.getValue =
|
||||||
|
|
@ -479,36 +480,41 @@ var EditSession = function(text, mode) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.undoChanges = function(deltas) {
|
this.undoChanges = function(deltas) {
|
||||||
this.selection.clearSelection();
|
if (!deltas.length)
|
||||||
|
return;
|
||||||
|
|
||||||
this.$fromUndo = true;
|
this.$fromUndo = true;
|
||||||
for (var i=deltas.length-1; i>=0; i--) {
|
this.doc.revertDeltas(deltas);
|
||||||
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.$fromUndo = false;
|
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.redoChanges = function(deltas) {
|
||||||
this.selection.clearSelection();
|
if (!deltas.length)
|
||||||
|
return;
|
||||||
|
|
||||||
this.$fromUndo = true;
|
this.$fromUndo = true;
|
||||||
for (var i=0; i<deltas.length; i++) {
|
this.doc.applyDeltas(deltas);
|
||||||
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.$fromUndo = false;
|
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) {
|
this.replace = function(range, text) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue