浏览代码

handle paste multi line and paste from excel formated numbers

Nicolas Cannasse 5 年之前
父节点
当前提交
f0cd9a8001
共有 1 个文件被更改,包括 19 次插入14 次删除
  1. 19 14
      hide/comp/cdb/Editor.hx

+ 19 - 14
hide/comp/cdb/Editor.hx

@@ -213,21 +213,26 @@ class Editor extends Component {
 				var col = columns[x];
 				if( !cursor.table.canEditColumn(col.name) )
 					continue;
-				var value : Dynamic = null;
-				switch( col.type ) {
-				case TId:
-					if( ~/^[A-Za-z0-9_]+$/.match(text) ) value = text;
-				case TString:
-					value = text;
-				case TInt:
-					value = Std.parseInt(text);
-				case TFloat:
-					value = Std.parseFloat(text);
-					if( Math.isNaN(value) ) value = null;
-				default:
-				}
-				if( value == null ) continue;
+				var lines = y1 == y2 ? [text] : text.split("\n");
 				for( y in y1...y2+1 ) {
+					var value : Dynamic = null;
+					var text = lines[y - y1];
+					if( text == null ) text = lines[lines.length - 1];
+					switch( col.type ) {
+					case TId:
+						if( ~/^[A-Za-z0-9_]+$/.match(text) ) value = text;
+					case TString:
+						value = text;
+					case TInt:
+						text = text.split(",").join("").split(" ").join("");
+						value = Std.parseInt(text);
+					case TFloat:
+						text = text.split(",").join("").split(" ").join("");
+						value = Std.parseFloat(text);
+						if( Math.isNaN(value) ) value = null;
+					default:
+					}
+					if( value == null ) continue;
 					var obj = sheet.lines[y];
 					Reflect.setField(obj, col.name, value);
 				}