[cmdpal] Fix calculator error when pressing Space (#39679)

Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
This commit is contained in:
Yu Leng
2025-05-26 11:37:38 +08:00
committed by GitHub
parent a804bf86a4
commit 718e725571
4 changed files with 18 additions and 1 deletions

View File

@@ -35,7 +35,7 @@ public static class CalculateHelper
{ {
if (string.IsNullOrWhiteSpace(input)) if (string.IsNullOrWhiteSpace(input))
{ {
throw new ArgumentNullException(paramName: nameof(input)); return false;
} }
if (!RegValidExpressChar.IsMatch(input)) if (!RegValidExpressChar.IsMatch(input))

View File

@@ -32,6 +32,11 @@ public static partial class QueryHelper
NumberTranslator translator = NumberTranslator.Create(inputCulture, new CultureInfo("en-US")); NumberTranslator translator = NumberTranslator.Create(inputCulture, new CultureInfo("en-US"));
var input = translator.Translate(query.Normalize(NormalizationForm.FormKC)); var input = translator.Translate(query.Normalize(NormalizationForm.FormKC));
if (string.IsNullOrWhiteSpace(input))
{
return ErrorHandler.OnError(isFallbackSearch, query, Properties.Resources.calculator_expression_empty);
}
if (!CalculateHelper.InputValid(input)) if (!CalculateHelper.InputValid(input))
{ {
return null; return null;

View File

@@ -132,6 +132,15 @@ namespace Microsoft.CmdPal.Ext.Calc.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Please enter an expression.
/// </summary>
public static string calculator_expression_empty {
get {
return ResourceManager.GetString("calculator_expression_empty", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Expression wrong or incomplete. /// Looks up a localized string similar to Expression wrong or incomplete.
/// </summary> /// </summary>

View File

@@ -199,4 +199,7 @@
<data name="calculator_copy_binary" xml:space="preserve"> <data name="calculator_copy_binary" xml:space="preserve">
<value>Copy binary</value> <value>Copy binary</value>
</data> </data>
<data name="calculator_expression_empty" xml:space="preserve">
<value>Please enter an expression</value>
</data>
</root> </root>