-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[Hosts] Add functionality to remove leading whitespace #37852
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?
Conversation
To resolve merge conflicts
This comment has been minimized.
This comment has been minimized.
@blakestack |
@htcfreek I think these null files are from when I tried to compile PowerToys locally, I accidentally left them in the PR along with the .prettierrc file. I will delete the draft and make a new draft PR. Apart from the null files, am I on the right track with the new feature? |
@blakestack Why using a drop-down box? I think an on/off toggle is the better choice. |
Resolve merge conflicts
@htcfreek Thank you, I will change it to a on/off toggle and then try to add tests |
This comment has been minimized.
This comment has been minimized.
public UserSettings() | ||
{ | ||
_settingsUtils = new SettingsUtils(); | ||
ShowStartupWarning = true; | ||
LoopbackDuplicates = false; | ||
AdditionalLinesPosition = HostsAdditionalLinesPosition.Top; | ||
Encoding = HostsEncoding.Utf8; | ||
AddLeadingWhitespace = false; |
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.
Isn't the current behavior "true"? We shouldn't change that.
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.
@htcfreek I will make these changes now
@@ -29,6 +32,7 @@ public HostsProperties() | |||
ShowStartupWarning = true; | |||
LaunchAdministrator = true; | |||
LoopbackDuplicates = false; | |||
AddLeadingWhitespace = false; |
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.
same: true and not false
else if (anyDisabled) && (AddLeadingWhitespace == false) | ||
{ | ||
lineBuilder.Append(e.line); |
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.
Wondering if this case simply should do nothing and is wrong/obsolete.
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.
I got confused with the logic here
the case is obsolete. I was thinking the program would hit the more restrictive condition first, and then adjust for the AddLeadingWhitespace
value
{ | ||
lineBuilder.Append(e.line); | ||
} | ||
else if (anyDisabled) |
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.
If the case above is obsolete you can use & !AddLeadingWhitespace
here.
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.
I will change this and then push the changes now
…update the behavior for adding or removing the Whitespace
@htcfreek I made the most recent changes. I am going to try compiling the program and see if it works. |
…g whitespaces from the code
I got the program to build, the console gave an error that said the |
In general, Toggle Switches are very often misused. They are designed to indicate an explicit ON and OFF state, as in turning a light on or off. The light stands for ACTION or WORK. Button, checkbox, or maybe a dropdown should be used for other cases. Therefore I say a toggleswitch is not appropriate for this situation. |
Why? We are turning white spaces on or off. |
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 adds functionality to remove leading whitespace from hosts entries by introducing a new boolean option.
- Adds the new "AddLeadingWhitespace" option in the settings UI and hosts properties.
- Integrates the option into the HostsService behavior for writing files.
- Adds test coverage to verify toggling the new whitespace removal functionality.
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs | Added a new property to expose the AddLeadingWhitespace setting. |
src/settings-ui/Settings.UI.Library/HostsProperties.cs | Introduced the new property with JSON conversion and default initialization. |
src/modules/Hosts/HostsUILib/Helpers/HostsService.cs | Declared a new field for AddLeadingWhitespace and used it in WriteAsync, but the field is never initialized from user settings. |
src/modules/Hosts/Hosts/Settings/UserSettings.cs | Added the new property with default value true in user settings initialization. |
src/modules/Hosts/Hosts.Tests/HostsServiceTest.cs | Added a test case to validate the whitespace removal behavior, though the mock instance appears to be mismatched. |
Files not reviewed (1)
- src/settings-ui/Settings.UI/SettingsXAML/Views/HostsPage.xaml: Language not supported
Co-authored-by: Copilot <[email protected]>
…Settings' in the constructor to ensure that the value reflects the users setting
resolve merge conflicts
@htcfreek I just made some changes to my PR. I made the changes that were suggested by copilot. Should I continue with the toggle switch implementation? |
@blakestack |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
I checked the errors from the azure-pipelines bot. I made an additional change to make the 'AddLeadingWhitespace' variable public on line 44 of the HostService.cs file. I believe that should resolve all the errors. |
This comment has been minimized.
This comment has been minimized.
Resolve merge conflicts
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, or 📝 job summary for details.Unrecognized words (39)
These words are not needed and should be removedcleanmgr CLSCTXINPROCALL CLSCTXLOCALSERVER FILELOCKSMITH IIDI iwr psexec smileys TEXTEXTRACTOR windowsterminal ZhiweiSome files were automatically ignored 🙈These sample patterns would exclude them:
You should consider adding them to:
File matching is via Perl regular expressions. To check these files, more of their words need to be in the dictionary than not. You can use To accept these unrecognized words as correct, update file exclusions, and remove the previously acknowledged and now absent words, you could run the following commands... in a clone of the [email protected]:blakestack/PowerToys.git repository curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/c635c2f3f714eec2fcf27b643a1919b9a811ef2e/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/16030752704/attempts/1' &&
git commit -m 'Update check-spelling metadata' Forbidden patterns 🙅 (2)In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves. These forbidden patterns matched content: Do not use
|
❌ Errors, Warnings, and Notices | Count |
---|---|
ℹ️ candidate-pattern | 1 |
❌ check-file-path | 20 |
❌ forbidden-pattern | 2 |
1 |
See ❌ Event descriptions for more information.
If the flagged items are 🤯 false positives
If items relate to a ...
-
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txt
file matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^
refers to the file's path from the root of the repository, so^README\.md$
would exclude README.md (on whichever branch you're using). -
well-formed pattern.
If you can write a pattern that would match it,
try adding it to thepatterns.txt
file.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.
Is there any way to skip the spellcheck job? |
@blakestack |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Summary of the Pull Request
Add functionality to remove leading whitespace:
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed