mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-03 21:08:18 +00:00
Add math expression evaluation to NumberInput boxes (#1472)
* Add math expression parsing to NumberInput boxes * Prevent NaN results * Add support for implicit multiplication in expressions
This commit is contained in:
parent
ab3410cffe
commit
2515620a77
4 changed files with 116 additions and 16 deletions
|
@ -2,6 +2,7 @@
|
|||
import { createEventDispatcher, onMount, onDestroy } from "svelte";
|
||||
|
||||
import { type NumberInputMode, type NumberInputIncrementBehavior } from "@graphite/wasm-communication/messages";
|
||||
import { evaluateMathExpression } from "@graphite-frontend/wasm/pkg/graphite_wasm.js";
|
||||
|
||||
import FieldInput from "@graphite/components/widgets/inputs/FieldInput.svelte";
|
||||
|
||||
|
@ -185,13 +186,11 @@
|
|||
// The `unFocus()` call at the bottom of this function and in `onTextChangeCanceled()` causes this function to be run again, so this check skips a second run.
|
||||
if (!editing) return;
|
||||
|
||||
const parsed = parseFloat(text);
|
||||
const newValue = Number.isNaN(parsed) ? undefined : parsed;
|
||||
|
||||
let newValue = evaluateMathExpression(text);
|
||||
if (newValue !== undefined && isNaN(newValue)) newValue = undefined; // Rejects `sqrt(-1)`
|
||||
updateValue(newValue);
|
||||
|
||||
editing = false;
|
||||
|
||||
self?.unFocus();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue