diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-07-27 15:34:19 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-07-27 15:34:19 +0800 |
| commit | 30f4a5fbf62c795d7d0142866b26e4427d4e9795 (patch) | |
| tree | 2fe8c7071ad780b00fa94ae38aa8ddd340226cf2 | |
| parent | 90df3a1a8738d61f747c50f26359ccabf0c7b229 (diff) | |
fix(mathcalc): disallow input == result
mathcalc: use display string instead of raw big string so it supports
scientific notation etc.
| -rw-r--r-- | qml_plugin/src/launcher/mathcalc.rs | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/qml_plugin/src/launcher/mathcalc.rs b/qml_plugin/src/launcher/mathcalc.rs index fd39ed1..623bf93 100644 --- a/qml_plugin/src/launcher/mathcalc.rs +++ b/qml_plugin/src/launcher/mathcalc.rs @@ -55,11 +55,12 @@ impl qobject::MathCalc { // TODO: consider moving to spawn_blocking RUNTIME.spawn( async move { + let input = input.to_string(); let result = parser::eval( &mut *ctx .lock() .await, - &input.to_string(), + &input, // TODO: move to const/config 53, ); @@ -72,22 +73,17 @@ impl qobject::MathCalc { r.map_or_default( |r| { let result: QString = r - .to_string_big() + .to_string() .into(); - QVariant::from(&result) + if result != input.into() { + QVariant::from(&result) + } else { + QVariant::default() + } }, ) }, - ), /* match result { - * Ok(value) => { - * let result: QString = value - * .to_string() - * .into(); - * QVariant::from(&result) - * } - * // TODO: add some logging - * Err(_) => QVariant::default(), - * }, */ + ), ) }, ) |
