Browse Source

save/restore cursor on undo

Nicolas Cannasse 7 years ago
parent
commit
4dfeed1fc7
2 changed files with 22 additions and 0 deletions
  1. 17 0
      hide/comp/cdb/Cursor.hx
  2. 5 0
      hide/comp/cdb/Editor.hx

+ 17 - 0
hide/comp/cdb/Cursor.hx

@@ -41,6 +41,23 @@ class Cursor {
 		return line.cells[x];
 		return line.cells[x];
 	}
 	}
 
 
+	public function save() {
+		return { sheet : table.sheet, x : x, y : y, select : select == null ? null : { x : select.x, y : select.y} };
+	}
+
+	public function load( s ) {
+		var table = null;
+		for( t in editor.tables )
+			if( t.sheet == s.sheet ) {
+				table = t;
+				break;
+			}
+		if( table == null )
+			return false;
+		set(table, s.x, s.y, s.select);
+		return true;
+	}
+
 	public function move( dx : Int, dy : Int, shift : Bool, ctrl : Bool ) {
 	public function move( dx : Int, dy : Int, shift : Bool, ctrl : Bool ) {
 		if( table == null )
 		if( table == null )
 			return;
 			return;

+ 5 - 0
hide/comp/cdb/Editor.hx

@@ -266,13 +266,18 @@ class Editor extends Component {
 		addChanges([{ ref : cursor.getLine().getChangeRef(), v : DeleteIndex(table.sheet.lines,index+1) }]);
 		addChanges([{ ref : cursor.getLine().getChangeRef(), v : DeleteIndex(table.sheet.lines,index+1) }]);
 		table.sheet.newLine(index);
 		table.sheet.newLine(index);
 		table.refresh();
 		table.refresh();
+		save();
 	}
 	}
 
 
 	public function popupColumn( table : Table, col : cdb.Data.Column ) {
 	public function popupColumn( table : Table, col : cdb.Data.Column ) {
 	}
 	}
 
 
 	public function addChanges( changes : cdb.Database.Changes ) {
 	public function addChanges( changes : cdb.Database.Changes ) {
+		var cs = cursor.save();
 		undo.change(Custom(function(undo) {
 		undo.change(Custom(function(undo) {
+			var ns = cursor.save();
+			cursor.load(cs);
+			cs = ns;
 			changes = base.applyChanges(changes);
 			changes = base.applyChanges(changes);
 			refresh();
 			refresh();
 		}));
 		}));