Skip to content

Conversation

@crramirez
Copy link

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 #FFBFAB or #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

  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Clipboard color detection and conversion:

  • Added ClipboardItemHelper.IsRgbHexColor method using a compiled regex to identify valid hex color strings in clipboard text. [1] [2]
  • Introduced HexColorConverterHelper.ConvertHexColorToRgb utility to convert hex color strings to Windows.UI.Color, handling both 3-digit and 6-digit formats.

UI enhancements for color previews:

  • Updated ClipboardHistoryItemPreviewControl to include a color preview grid that displays an ellipse filled with the detected color and the color code as text, using the new HexColorToBrushConverter. [1] [2] [3]
  • Modified logic in ClipboardHistoryItemPreviewControl.xaml.cs to 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:

  • Added unit tests for hex color 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

  • Copied to the clipboard a color encoded text like: #FFBFAB
  • Opened Advanced Paste and noticed the color:
image

* 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 <8397379+crramirez@users.noreply.github.com>

* Optimize regex performance with compiled static instance

Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>

* 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 <8397379+crramirez@users.noreply.github.com>

* 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] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Co-authored-by: Carlos Ramirez <crramirez@gmail.com>
Copilot AI review requested due to automatic review settings November 30, 2025 21:37
Copilot finished reviewing on behalf of crramirez November 30, 2025 21:39
Copy link
Contributor

Copilot AI left a 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

crramirez and others added 2 commits November 30, 2025 23:39
…elper.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…sts/HexColorToColorConverterTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jiripolasek
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jiripolasek jiripolasek added the Product-Advanced Paste Refers to the Advanced Paste module label Dec 1, 2025
@jiripolasek
Copy link
Collaborator

Hello @crramirez, the build failed during "Verify XAML formatting." Check out https://github.com/microsoft/PowerToys/blob/main/doc/devdocs/style.md for details.

@jiripolasek jiripolasek changed the title Add RGB hex color preview to Advanced Paste clipboard history (#1) Add RGB hex color preview to Advanced Paste clipboard history Dec 1, 2025
…adhere to consistent formatting standards.
@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 43990 in repo microsoft/PowerToys

@crramirez
Copy link
Author

@jiripolasek Ready

@vanzue
Copy link
Contributor

vanzue commented Dec 2, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jiripolasek
Copy link
Collaborator

@crramirez Build failed, StyleCop strikes again:

HexColorToColorConverterTests.cs(13,1): Error SA1505: An opening brace should not be followed by a blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1505.md)

@crramirez
Copy link
Author

@jiripolasek @vanzue Fixed!

@jiripolasek
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-Advanced Paste Refers to the Advanced Paste module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Advanced Paste] Show color indicator if the text represents a color encoded in text like #FFBFAB

3 participants