From 30f4a5fbf62c795d7d0142866b26e4427d4e9795 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Mon, 27 Jul 2026 15:34:19 +0800 Subject: fix(mathcalc): disallow input == result mathcalc: use display string instead of raw big string so it supports scientific notation etc. --- qml_plugin/src/launcher/mathcalc.rs | 22 +++++++++------------- 1 file 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(), - * }, */ + ), ) }, ) -- cgit v1.2.3