-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Add 'Replace input if query ends with =' feature to Command Palette Calculator #44038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add 'Replace input if query ends with =' feature to Command Palette Calculator #44038
Conversation
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR ports the "Replace input if query ends with '='" feature from PowerToys Run Calculator to the Command Palette Calculator extension. When enabled (default: true), typing an expression ending with = automatically replaces the input with the calculated result, enabling seamless calculation chaining (e.g., 5*3= → 15, then 15+2= → 17).
Key Changes:
- Added
ReplaceInputOnEqualsboolean setting to the calculator settings interface - Modified
UpdateSearchTextto detect '=' suffix, process expression without it, and replace search text with result - Leveraged existing
skipQuerySearchTextmechanism to prevent recursive update calls
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/ISettingsInterface.cs | Added ReplaceInputOnEquals property to settings interface |
| src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/SettingsManager.cs | Registered new toggle setting with default value of true |
| src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Pages/CalculatorListPage.cs | Implemented replace-on-equals logic in UpdateSearchText method using existing skipQuerySearchText pattern |
| // Check if query ends with '=' and setting is enabled | ||
| bool replaceInput = _settingsManager.ReplaceInputOnEquals && newSearch.EndsWith('='); | ||
| string queryToProcess = replaceInput ? newSearch[..^1] : newSearch; | ||
|
|
||
| _emptyItem.Subtitle = queryToProcess; | ||
|
|
||
| var result = QueryHelper.Query(queryToProcess, _settingsManager, false, HandleSave); | ||
|
|
||
| // If replace input is enabled and we have a valid result, replace the search text with the result | ||
| if (replaceInput && result is not null && !string.IsNullOrEmpty(result.Title)) | ||
| { | ||
| skipQuerySearchText = result.Title; | ||
| SearchText = result.Title; | ||
| } |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new "Replace input if query ends with '='" feature lacks test coverage. Since this extension has comprehensive unit tests in Microsoft.CmdPal.Ext.Calc.UnitTests (with tests for UpdateSearchText in QueryTests.cs), tests should be added to verify:
- When
ReplaceInputOnEqualsis enabled and query ends with '=', the search text is replaced with the result (e.g., "5*3=" → "15") - When
ReplaceInputOnEqualsis disabled, query ending with '=' is processed normally - Edge cases like "=" (empty expression) or invalid expressions with '=' don't cause issues
Example test structure:
[TestMethod]
public void ReplaceInputOnEqualsEnabledTest()
{
var settings = new Settings(replaceInputOnEquals: true);
var page = new CalculatorListPage(settings);
page.UpdateSearchText(string.Empty, "5*3=");
Assert.AreEqual("15", page.SearchText);
}|
🟥 I don't think this works as intended: Screen.Recording.2025-12-03.132307.mp4Screen.Recording.2025-12-03.123650.mp4 |
|
@jiripolasek Thanks for testing and catching this issue! I see the problem now. Looking at the PowerToys Run Calculator implementation, they use In my current implementation, when Let me investigate further how Command Palette handles search text changes vs PowerToys Run's
I'll work on a fix and update this PR. Thanks for the video - it clearly shows the issue! |
|
I've pushed a fix - the issue was that after setting UpdateResult(replacementResult);after setting the skip flag. This ensures the calculated result is displayed when the search text is replaced. Please re-test when you have a chance! 🙏 |
3ec113e to
28e33cf
Compare
|
@ThanhNguyxn |
|
@jiripolasek Good catch! The test Settings class was missing the I've pushed a fix (commit 07856a4) that adds:
The unit tests should pass now. Unfortunately I can't run them locally (VS 2018 Preview has a C++ toolset issue), so I'll wait for CI to confirm. If there are any other test issues, please let me know! |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
679b102 to
e001f5a
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
e001f5a to
28e0b34
Compare
…alculator This commit ports the 'Replace input if query ends with =' feature from PowerToys Run Calculator plugin to the Command Palette Calculator extension. When enabled (default: true), typing an expression ending with '=' will automatically replace the input with the calculated result, allowing users to chain calculations more seamlessly. Changes: - Add ReplaceInputOnEquals setting to ISettingsInterface - Add toggle setting in SettingsManager (default: enabled) - Update CalculatorListPage.UpdateSearchText to handle queries ending with '=' - Resource strings already exist in Resources.resx Fixes microsoft#43460
28e0b34 to
a83dc44
Compare
Summary of the Pull Request
This PR ports the "Replace input if query ends with '='" feature from PowerToys Run Calculator plugin to the Command Palette Calculator extension.
References and Relevant Issues
Fixes #43460
Detailed Description of the Pull Request / Additional comments
Feature Description
When enabled (default: true), typing an expression ending with
=will automatically replace the input with the calculated result, allowing users to chain calculations more seamlessly.Example: Typing
5*3-2=will change the query to13, allowing you to continue with13+7=→20Changes Made
ReplaceInputOnEqualsproperty to the settings interface_replaceInputOnEqualstoggle setting (default: enabled)UpdateSearchTextmethod to:==Notes
calculator_settings_replace_inputandcalculator_settings_replace_input_description) already exist inResources.resxValidation Steps Performed