mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-25 16:09:54 +01:00
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## 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. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #43538 <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **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 - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## 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]](diffhunk://#diff-7429196ad30cd0bce57b102669da4dc13d43a09579e99ceac7cc0f7dc101cd2bR62-R86) [[2]](diffhunk://#diff-7429196ad30cd0bce57b102669da4dc13d43a09579e99ceac7cc0f7dc101cd2bR112-R114) * 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]](diffhunk://#diff-2ed6014d4c17037b9cd0ab397e40b9069b1e7fe47a700673f34e8217d78124d5R29-R48) [[2]](diffhunk://#diff-2ed6014d4c17037b9cd0ab397e40b9069b1e7fe47a700673f34e8217d78124d5R14) [[3]](diffhunk://#diff-0c26c92697f6bb38fa40160fc8b18f0876ddc8d828a510034411001aa2e05063R1-R28) * 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]](diffhunk://#diff-d81d997d5fb414f1563c31c38681113aaa9c847ef05bb77662d30bd1310d6b8eR1-R61) [[2]](diffhunk://#diff-185e8954ca6f061bf5d60d0c61ac6cfd87bd1a48ebda11a8172e3496a050fe85R1-R36) <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed * Copied to the clipboard a color encoded text like: #FFBFAB * Opened Advanced Paste and noticed the color: <img width="467" height="309" alt="image" src="https://github.com/user-attachments/assets/6cedce89-9833-4efb-abf9-3cfe8e8f32f0" /> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>