From 3e5552b7f3d6e4a21c893dca1e34516e7c965e6a Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sun, 3 May 2026 20:16:38 +0545 Subject: [PATCH] fix(src/window/launcher/plugins): refine calculator unit conversion parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The updated regex now matches non‑numeric unit prefixes, and units are normalized before conversion, improving accuracy and preventing mismatches. - Bug Fixes: Fixed incorrect unit detection that caused failed conversions. - Enhancements: Added unit cleaning (`converter.clean_type`) to standardize input. - New Features: None. --- src/window/launcher/plugins/calculator.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/window/launcher/plugins/calculator.py b/src/window/launcher/plugins/calculator.py index 566e0c7..342c493 100644 --- a/src/window/launcher/plugins/calculator.py +++ b/src/window/launcher/plugins/calculator.py @@ -48,7 +48,7 @@ class CalculatorPlugin(PluginBase): self.expression_pattern = re.compile(r"[\d+\-*/^()=]") self.number_pattern = re.compile(r"\d") self.conversion_pattern = re.compile( - r"(\d+(?:\.\d+)?)\s*([a-zA-Z]+)\s*(?:to|in|=)\s*([a-zA-Z]+)" + r"(\d+(?:\.\d+)?)\s*([^0-9\s]+)\s*(?:to|in|=)\s*([^0-9\s]+)" ) # Cache for conversion results @@ -89,7 +89,11 @@ class CalculatorPlugin(PluginBase): subtitle = f"{value} {from_unit} = {result:.6g} {to_unit}" else: # Use the conversion utility - result = self.converter.convert(value, from_unit, to_unit) + from_unit_clean = self.converter.clean_type(from_unit) + to_unit_clean = self.converter.clean_type(to_unit) + result = self.converter.convert( + value, from_unit_clean, to_unit_clean + ) # Cache the result self._conversion_cache[cache_key] = result subtitle = f"{value} {from_unit} = {result:.6g} {to_unit}"