Browse Source

added Table.getRootLine()

Nicolas Cannasse 11 tháng trước cách đây
mục cha
commit
92f31c0e9d
2 tập tin đã thay đổi với 14 bổ sung13 xóa
  1. 2 7
      hide/comp/cdb/Cell.hx
  2. 12 6
      hide/comp/cdb/Line.hx

+ 2 - 7
hide/comp/cdb/Cell.hx

@@ -103,14 +103,9 @@ class Cell {
 		function displayError(msg:String) {
 			ide.quickError(msg);
 		}
-		var rootLine = line;
-		while(true) {
-			var t = Std.downcast(rootLine.table, SubTable);
-			if( t == null ) break;
-			rootLine = t.cell.line;
-		}
+		var rootLine = line.getRootLine();
 		var newV : Float = try editor.formulas.evalBlock(() -> {
-			var obj = @:privateAccess editor.formulas.remap(rootLine.obj, table.sheet);
+			var obj = @:privateAccess editor.formulas.remap(rootLine.obj, rootLine.table.sheet);
 			f.call(obj);
 		})
 		catch( e : hscript.Expr.Error ) { displayError(e.toString()); Math.NaN; }

+ 12 - 6
hide/comp/cdb/Line.hx

@@ -61,12 +61,8 @@ class Line extends Component {
 	}
 
 	public function getGroupID() {
-		var t = table;
-		var line = this;
-		while( t.parent != null ) {
-			line = Std.downcast(t, SubTable).cell.line;
-			t = t.parent;
-		}
+		var line = getRootLine();
+		var t = line.table;
 		for( i in 0...t.sheet.separators.length ) {
 			var sep = t.sheet.separators[t.sheet.separators.length - 1 - i];
 			if( sep.index <= line.index ) {
@@ -79,6 +75,16 @@ class Line extends Component {
 		return null;
 	}
 
+	public function getRootLine() {
+		var line = this;
+		var t = table;
+		while( t.parent != null ) {
+			line = Std.downcast(t, SubTable).cell.line;
+			t = t.parent;
+		}
+		return line;
+	}
+
 	public function getConstants( objId ) {
 		var consts = [
 			"cdb.objID" => objId,