Skip to content

Commit 9be2c84

Browse files
authored
Merge pull request #358 from omar92/allow-equations-in-number-inputs
try solve the numbers equations
2 parents 492b7a5 + ca1d754 commit 9be2c84

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/litegraph.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9990,7 +9990,14 @@ LGraphNode.prototype.executeAction = function(action)
99909990
var delta = x < 40 ? -1 : x > widget_width - 40 ? 1 : 0;
99919991
if (event.click_time < 200 && delta == 0) {
99929992
this.prompt("Value",w.value,function(v) {
9993-
inner_value_change(this, this.value);
9993+
// check if v is a valid equation or a number
9994+
if (/^[0-9+\-*/()\s]+$/.test(v)) {
9995+
try {//solve the equation if possible
9996+
v = eval(v);
9997+
} catch (e) { }
9998+
}
9999+
this.value = Number(v);
10000+
inner_value_change(this, this.value);
999410001
}.bind(w),
999510002
event);
999610003
}

0 commit comments

Comments
 (0)