-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Add RGB hex color preview to Advanced Paste clipboard history #43990
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
* Initial plan * Add color preview feature for RGB hex colors in clipboard history - Added IsRgbHexColor() method to ClipboardItemHelper to detect hex colors - Extended ClipboardItem model with ColorHex property - Created HexColorToBrushConverter to convert hex colors to brushes - Updated ClipboardHistoryItemPreviewControl to display color square - Modified MainPage to detect and populate color info when loading history - Added unit tests for color detection and converter Co-authored-by: crramirez <[email protected]> * Optimize regex performance with compiled static instance Co-authored-by: crramirez <[email protected]> * Show color rectangle alongside text in grid layout - Added HasColorWithText property to show both color and text together - Updated XAML to use a grid with two columns for color preview - Color rectangle (32x32) in first column, text in second column - Rectangle aligned to left with 8px margins and 4px corner radius - Text set to NoWrap for cleaner appearance with color preview Co-authored-by: crramirez <[email protected]> * Make HexColorToBrushConverter a partial class Updated the `HexColorToBrushConverter` class to be a `partial` class by adding the `partial` keyword to its declaration. This change enables the class to be split across multiple files, improving code organization and allowing for potential platform-specific implementations. No changes were made to the class's functionality. * Refactor hex color handling: centralize validation logic, simplify converters, and remove unused `ColorHex` property. * Replace HexColorToBrushConverter with HexColorConverterHelper, update tests, and refine hex color validation logic * Add HexColorConverterHelper for hex-to-RGB color conversion utility * Refactor hex color handling: use `GeneratedRegex` for `HexColorRegex`, update `ClipboardItemHelper` for partial methods, and optimize item creation logic. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: crramirez <[email protected]> Co-authored-by: Carlos Ramirez <[email protected]>
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 pull request adds RGB hex color code detection and preview functionality to the Advanced Paste clipboard history feature. When users copy a valid hex color code (like #FFBFAB or #abc) to the clipboard, Advanced Paste now displays a visual color preview with the color's hex value in the clipboard history UI.
Key changes:
- Implements regex-based color detection for 3-digit and 6-digit hex color codes
- Adds color conversion utilities to transform hex strings into displayable colors
- Updates the clipboard preview UI to show a color ellipse and text for detected colors
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| ClipboardItemHelper.cs | Adds IsRgbHexColor method with compiled regex to detect valid hex color strings |
| HexColorConverterHelper.cs | New helper class to convert hex color strings to Windows.UI.Color objects |
| HexColorToBrushConverter.cs | New XAML converter that transforms hex color strings into SolidColorBrush for UI binding |
| ClipboardHistoryItemPreviewControl.xaml | Adds color preview grid with ellipse and text display for hex colors |
| ClipboardHistoryItemPreviewControl.xaml.cs | Adds HasColor property and updates visibility logic for color vs text/glyph previews |
| ClipboardItemHelperTests.cs | Comprehensive unit tests for hex color detection covering valid, invalid, and edge cases |
| HexColorToColorConverterTests.cs | Unit tests for color conversion logic including 3-digit and 6-digit hex formats |
src/modules/AdvancedPaste/AdvancedPaste/Helpers/ClipboardItemHelper.cs
Outdated
Show resolved
Hide resolved
src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Converters/HexColorConverterHelper.cs
Show resolved
Hide resolved
src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Converters/HexColorConverterHelper.cs
Show resolved
Hide resolved
...dules/AdvancedPaste/AdvancedPaste.UnitTests/ConvertersTests/HexColorToColorConverterTests.cs
Outdated
Show resolved
Hide resolved
…elper.cs Co-authored-by: Copilot <[email protected]>
…sts/HexColorToColorConverterTests.cs Co-authored-by: Copilot <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Hello @crramirez, the build failed during "Verify XAML formatting." Check out https://github.com/microsoft/PowerToys/blob/main/doc/devdocs/style.md for details. |
…adhere to consistent formatting standards.
|
Commenter does not have sufficient privileges for PR 43990 in repo microsoft/PowerToys |
|
@jiripolasek Ready |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@crramirez Build failed, StyleCop strikes again: |
…mprove code readability.
|
@jiripolasek @vanzue Fixed! |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Summary of the Pull Request
This pull request adds support for recognizing and displaying clipboard items that are valid RGB hex color codes (such as
#FFBFABor#abc) in the Advanced Paste module. It introduces logic to detect hex color strings, converts them to color values, and updates the UI to show a color preview for these items. The changes also include comprehensive unit tests for the new functionality.PR Checklist
Detailed Description of the Pull Request / Additional comments
Clipboard color detection and conversion:
ClipboardItemHelper.IsRgbHexColormethod using a compiled regex to identify valid hex color strings in clipboard text. [1] [2]HexColorConverterHelper.ConvertHexColorToRgbutility to convert hex color strings toWindows.UI.Color, handling both 3-digit and 6-digit formats.UI enhancements for color previews:
ClipboardHistoryItemPreviewControlto include a color preview grid that displays an ellipse filled with the detected color and the color code as text, using the newHexColorToBrushConverter. [1] [2] [3]ClipboardHistoryItemPreviewControl.xaml.csto ensure color previews are shown only for detected color items and to adjust visibility of text and glyph previews accordingly.Unit tests for color detection and conversion:
HexColorToColorConverterTests.cs) and color detection logic (ClipboardItemHelperTests.cs) to verify correct behavior for valid, invalid, and edge-case inputs. [1] [2]Validation Steps Performed