fix undoManager wip

This commit is contained in:
nightwing 2012-08-31 12:44:00 +04:00
commit 4c3519de29
5 changed files with 19 additions and 15 deletions

View file

@ -246,7 +246,6 @@ var EditSession = function(text, mode) {
this.selection.clearSelection(); this.selection.clearSelection();
this.$resetRowCache(0); this.$resetRowCache(0);
this.$deltas = [];
this.$deltasDoc = []; this.$deltasDoc = [];
this.$deltasFold = []; this.$deltasFold = [];
this.getUndoManager().reset(); this.getUndoManager().reset();
@ -343,7 +342,6 @@ var EditSession = function(text, mode) {
**/ **/
this.setUndoManager = function(undoManager) { this.setUndoManager = function(undoManager) {
this.$undoManager = undoManager; this.$undoManager = undoManager;
this.$deltas = [];
this.$deltasDoc = []; this.$deltasDoc = [];
this.$deltasFold = []; this.$deltasFold = [];
@ -358,10 +356,9 @@ var EditSession = function(text, mode) {
* *
**/ **/
this.$syncInformUndoManager = function() { this.$syncInformUndoManager = function() {
self.$informUndoManager.cancel(); var $deltas = [];
if (self.$deltasFold.length) { if (self.$deltasFold.length) {
self.$deltas.push({ $deltas.push({
group: "fold", group: "fold",
deltas: self.$deltasFold deltas: self.$deltasFold
}); });
@ -369,17 +366,17 @@ var EditSession = function(text, mode) {
} }
if (self.$deltasDoc.length) { if (self.$deltasDoc.length) {
self.$deltas.push({ $deltas.push({
group: "doc", group: "doc",
deltas: self.$deltasDoc deltas: self.$deltasDoc
}); });
self.$deltasDoc = []; self.$deltasDoc = [];
} }
if (self.$deltas.length > 0) { if ($deltas.length > 0) {
undoManager.execute({ undoManager.execute({
action: "aceupdate", action: "aceupdate",
args: [self.$deltas, self] args: [$deltas, self]
}); });
} }

View file

@ -84,12 +84,13 @@ var Editor = function(renderer, session) {
this.keyBinding = new KeyBinding(this); this.keyBinding = new KeyBinding(this);
// TODO detect touch event support // TODO detect touch event support
if (useragent.isIPad) { /* if (useragent.isIPad) {
//this.$mouseHandler = new TouchHandler(this); //this.$mouseHandler = new TouchHandler(this);
} else { } else {
this.$mouseHandler = new MouseHandler(this);
new FoldHandler(this); } */
} this.$mouseHandler = new MouseHandler(this);
new FoldHandler(this);
this.$blockScrolling = 0; this.$blockScrolling = 0;
this.$search = new Search().set({ this.$search = new Search().set({
@ -689,6 +690,10 @@ var Editor = function(renderer, session) {
this._emit("paste", text); this._emit("paste", text);
this.insert(text); this.insert(text);
}; };
this.execCommand = function(cmd, args) {
return this.commands.exec(cmd, this, args);
};
/** /**
* Editor.insert(text) * Editor.insert(text)

View file

@ -145,7 +145,7 @@ var TextInput = function(parentNode, host) {
var copyText = host.getCopyText(); var copyText = host.getCopyText();
if(copyText) { if(copyText) {
text.value = copyText; text.value = copyText;
host.onCopy(copyText); host.execCommand("copy", copyText);
} else } else
e.preventDefault(); e.preventDefault();
reset(); reset();
@ -159,7 +159,7 @@ var TextInput = function(parentNode, host) {
var copyText = host.getCopyText(); var copyText = host.getCopyText();
if(copyText) { if(copyText) {
text.value = copyText; text.value = copyText;
host.onCut(copyText); host.execCommand("cut", copyText);
} else } else
e.preventDefault(); e.preventDefault();
reset(); reset();

View file

@ -62,7 +62,7 @@ var MouseHandler = function(editor) {
var mouseTarget = editor.renderer.getMouseEventTarget(); var mouseTarget = editor.renderer.getMouseEventTarget();
event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click")); event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove")); event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"));
event.addMultiMouseDownListener(mouseTarget, [300, 300, 250], this, "onMouseEvent"); event.addMultiMouseDownListener(mouseTarget, [350, 300, 250], this, "onMouseEvent");
event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel")); event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
var gutterEl = editor.renderer.$gutter; var gutterEl = editor.renderer.$gutter;

View file

@ -82,6 +82,7 @@ var UndoManager = function() {
* [Perform an undo operation on the document, reverting the last change. Returns the range of the undo.]{: #UndoManager.undo} * [Perform an undo operation on the document, reverting the last change. Returns the range of the undo.]{: #UndoManager.undo}
**/ **/
this.undo = function(dontSelect) { this.undo = function(dontSelect) {
this.$doc.$syncInformUndoManager();
var deltas = this.$undoStack.pop(); var deltas = this.$undoStack.pop();
var undoSelectionRange = null; var undoSelectionRange = null;
if (deltas) { if (deltas) {
@ -99,6 +100,7 @@ var UndoManager = function() {
* [Perform a redo operation on the document, reimplementing the last change.]{: #UndoManager.redo} * [Perform a redo operation on the document, reimplementing the last change.]{: #UndoManager.redo}
**/ **/
this.redo = function(dontSelect) { this.redo = function(dontSelect) {
this.$doc.$syncInformUndoManager();
var deltas = this.$redoStack.pop(); var deltas = this.$redoStack.pop();
var redoSelectionRange = null; var redoSelectionRange = null;
if (deltas) { if (deltas) {