[PR #13429] [MERGED] Implement EnableColorSelection #29540

Open
opened 2026-01-31 09:35:30 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/13429
Author: @jazzdelightsme
Created: 7/5/2022
Status: Merged
Merged: 9/1/2022
Merged by: @undefined

Base: mainHead: dev/danthom/enableColorSelection


📝 Commits (10+)

  • b5a59c0 Implement EnableColorSelection
  • e4271f1 first (failed) attempt: put it in ControlCore.idl (Control::MatchMode)
  • 3320c1a Fix compilation with new MatchMode enum
  • a08339a Merge remote-tracking branch 'origin/main' into dev/danthom/enableColorSelection
  • c7c8668 Fix invalid exec command in vcxproj
  • 84fb3a7 Fix color selection settings error
  • d766d6c Allow til::from_wchars to work with chars
  • 715ee3e Various changes feat. lhecker
  • f2a0d7b just a little oops (transposed start and end coords in comparison)
  • 1915ca9 [ActionMap] remove FAIL_FAST on >1 parent

📊 Changes

35 files changed (+1073 additions, -43 deletions)

View changed files

📝 .github/actions/spelling/allow/apis.txt (+1 -0)
📝 doc/cascadia/profiles.schema.json (+65 -13)
📝 src/buffer/out/LineRendition.hpp (+7 -0)
📝 src/buffer/out/search.cpp (+6 -7)
📝 src/buffer/out/search.h (+3 -3)
📝 src/buffer/out/textBuffer.cpp (+103 -4)
📝 src/buffer/out/textBuffer.hpp (+5 -0)
📝 src/cascadia/TerminalApp/AppActionHandlers.cpp (+15 -0)
📝 src/cascadia/TerminalControl/ControlCore.cpp (+49 -0)
📝 src/cascadia/TerminalControl/ControlCore.h (+13 -0)
📝 src/cascadia/TerminalControl/ControlCore.idl (+11 -0)
📝 src/cascadia/TerminalControl/TermControl.cpp (+4 -0)
📝 src/cascadia/TerminalControl/TermControl.h (+2 -0)
📝 src/cascadia/TerminalControl/TermControl.idl (+2 -0)
📝 src/cascadia/TerminalCore/ICoreAppearance.idl (+6 -0)
📝 src/cascadia/TerminalCore/Terminal.cpp (+36 -0)
📝 src/cascadia/TerminalCore/Terminal.hpp (+4 -0)
📝 src/cascadia/TerminalCore/TerminalSelection.cpp (+29 -7)
📝 src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp (+2 -0)
📝 src/cascadia/TerminalSettingsModel/ActionArgs.cpp (+116 -0)

...and 15 more files

📄 Description

Summary of the Pull Request

As described in #9583, this change implements the legacy conhost "EnableColorSelection" feature.

Detailed Description of the Pull Request / Additional comments

@zadjii-msft was super nice and provided the outline/plumbing (WinRT classes and such) as a hackathon-type project (thank you!)--a "SelectionColor" runtimeclass, a ColorSelection method on the ControlCore runtimeclass, associated plumbing through the layers; plus the action-and-args plumbing to allow hooking up a basic "ColorSelection" action, which allows you to put actions in your settings JSON like so:

{
    "command":
    {
        "action": "experimental.colorSelection",
        "foreground": "#0f3"
    },
    "keys": "alt+4"
},

On top of that foundation, I added a couple of things:

  • The ability to specify indexes for colors, in addition to RGB and RRGGBB colors.
    • It's a bit hacky, because there are some conversions that fight against sneaking an "I'm an index" flag in the alpha channel.
  • A new "matchMode" parameter on the action, allowing you to say if you want to only color the current selection ("0") or all matches ("1").
    • I made it an int, because I'd like to enable at least one other "match mode" later, but it requires me/someone to fix up search.cpp to handle regex first.
    • Search used an old UIA "ColorSelection" method which was previously E_NOTIMPL, but is now wired up. Don't know what/if anything else uses this.
  • An uber-toggle setting, "EnableColorSelection", which allows you to set a single bool in your settings JSON, to light up all the keybindings you would expect from the legacy "EnableColorSelection" feature:
    • alt+[0..9]: color foreground
    • alt+shift+[0..9]: color foreground, all matches
    • ctrl+[0..9]: color background
    • ctrl+shift+[0..9]: color background, all matches
  • A few of the actions cannot be properly invoked via their keybindings, due to #13124. *!* But they work if you do them from the command palette.
  • If you have "EnableColorSelection : true" in your settings JSON, but then specify a different action in your JSON that uses the same key binding as a color selection keybinding, your custom one wins, which I think is the right thing.
  • I fixed what I think was a bug in search.cpp, which also affected the legacy EnableColorSelection feature: due to a non-inclusive coordinate comparison, you were not allowed to color a single character; but I see no reason why that should be disallowed. Now you can make all your Xs red if you like.

"Soft" spots:

  • I was a bit surprised at some of the helpers I had to provide in textBuffer.cpp. Perhaps there are existing methods that I didn't find?
  • Localization? Because there are so many (40!) actions, I went to some trouble to try to provide nice command/arg descriptions. But I don't know how localization works…

PR Checklist

  • Closes wordDelimiters not working, always breaks on a dot '.' or dash '-' (#9583)
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed (what would be the right place to add tests for this?)
  • Documentation updated. If checked, please file a pull request on our docs repo and link it here: #xxx
  • Schema updated. (is this needed?)
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

Validation Steps Performed

Just manual testing.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/13429 **Author:** [@jazzdelightsme](https://github.com/jazzdelightsme) **Created:** 7/5/2022 **Status:** ✅ Merged **Merged:** 9/1/2022 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/danthom/enableColorSelection` --- ### 📝 Commits (10+) - [`b5a59c0`](https://github.com/microsoft/terminal/commit/b5a59c03fe49f29072d5550c07eb033656183628) Implement EnableColorSelection - [`e4271f1`](https://github.com/microsoft/terminal/commit/e4271f1d550280b22a1166b97201a5d8fdc4bac5) first (failed) attempt: put it in ControlCore.idl (Control::MatchMode) - [`3320c1a`](https://github.com/microsoft/terminal/commit/3320c1ad6dbc674e4daef7914c6e25bd47767952) Fix compilation with new MatchMode enum - [`a08339a`](https://github.com/microsoft/terminal/commit/a08339ae69958d2c609deed4a35f2022671931cf) Merge remote-tracking branch 'origin/main' into dev/danthom/enableColorSelection - [`c7c8668`](https://github.com/microsoft/terminal/commit/c7c86682a6ce4d1d91b40e5d664df1633a18cf8a) Fix invalid exec command in vcxproj - [`84fb3a7`](https://github.com/microsoft/terminal/commit/84fb3a783a4d0ba1b2ff5591cc8767e7cfc62d87) Fix color selection settings error - [`d766d6c`](https://github.com/microsoft/terminal/commit/d766d6c39775cd7fd0ab3687f9cf216fc10bed8c) Allow til::from_wchars to work with chars - [`715ee3e`](https://github.com/microsoft/terminal/commit/715ee3eefbf4f96bc6007567e5121c57a8aafe6a) Various changes feat. lhecker - [`f2a0d7b`](https://github.com/microsoft/terminal/commit/f2a0d7b81d812dbaa4b937e5be82b41962d05504) just a little oops (transposed start and end coords in comparison) - [`1915ca9`](https://github.com/microsoft/terminal/commit/1915ca94b59d75ac5bc28e033755fd90b0651c93) [ActionMap] remove FAIL_FAST on >1 parent ### 📊 Changes **35 files changed** (+1073 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `.github/actions/spelling/allow/apis.txt` (+1 -0) 📝 `doc/cascadia/profiles.schema.json` (+65 -13) 📝 `src/buffer/out/LineRendition.hpp` (+7 -0) 📝 `src/buffer/out/search.cpp` (+6 -7) 📝 `src/buffer/out/search.h` (+3 -3) 📝 `src/buffer/out/textBuffer.cpp` (+103 -4) 📝 `src/buffer/out/textBuffer.hpp` (+5 -0) 📝 `src/cascadia/TerminalApp/AppActionHandlers.cpp` (+15 -0) 📝 `src/cascadia/TerminalControl/ControlCore.cpp` (+49 -0) 📝 `src/cascadia/TerminalControl/ControlCore.h` (+13 -0) 📝 `src/cascadia/TerminalControl/ControlCore.idl` (+11 -0) 📝 `src/cascadia/TerminalControl/TermControl.cpp` (+4 -0) 📝 `src/cascadia/TerminalControl/TermControl.h` (+2 -0) 📝 `src/cascadia/TerminalControl/TermControl.idl` (+2 -0) 📝 `src/cascadia/TerminalCore/ICoreAppearance.idl` (+6 -0) 📝 `src/cascadia/TerminalCore/Terminal.cpp` (+36 -0) 📝 `src/cascadia/TerminalCore/Terminal.hpp` (+4 -0) 📝 `src/cascadia/TerminalCore/TerminalSelection.cpp` (+29 -7) 📝 `src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp` (+2 -0) 📝 `src/cascadia/TerminalSettingsModel/ActionArgs.cpp` (+116 -0) _...and 15 more files_ </details> ### 📄 Description ## Summary of the Pull Request As described in #9583, this change implements the legacy conhost "EnableColorSelection" feature. ## Detailed Description of the Pull Request / Additional comments @zadjii-msft was super nice and provided the outline/plumbing (WinRT classes and such) as a hackathon-type project (thank you!)--a "SelectionColor" runtimeclass, a ColorSelection method on the ControlCore runtimeclass, associated plumbing through the layers; plus the action-and-args plumbing to allow hooking up a basic "ColorSelection" action, which allows you to put actions in your settings JSON like so: ```json { "command": { "action": "experimental.colorSelection", "foreground": "#0f3" }, "keys": "alt+4" }, ``` On top of that foundation, I added a couple of things: * The ability to specify indexes for colors, in addition to RGB and RRGGBB colors. - It's a bit hacky, because there are some conversions that fight against sneaking an "I'm an index" flag in the alpha channel. * A new "matchMode" parameter on the action, allowing you to say if you want to only color the current selection ("0") or all matches ("1"). - I made it an int, because I'd like to enable at least one other "match mode" later, but it requires me/someone to fix up search.cpp to handle regex first. - Search used an old UIA "ColorSelection" method which was previously `E_NOTIMPL`, but is now wired up. Don't know what/if anything else uses this. * An uber-toggle setting, "EnableColorSelection", which allows you to set a single `bool` in your settings JSON, to light up all the keybindings you would expect from the legacy "EnableColorSelection" feature: - alt+[0..9]: color foreground - alt+shift+[0..9]: color foreground, all matches - ctrl+[0..9]: color background - ctrl+shift+[0..9]: color background, all matches * A few of the actions cannot be properly invoked via their keybindings, due to #13124. `*!*` But they work if you do them from the command palette. * If you have "`EnableColorSelection : true`" in your settings JSON, but then specify a different action in your JSON that uses the same key binding as a color selection keybinding, your custom one wins, which I think is the right thing. * I fixed what I think was a bug in search.cpp, which also affected the legacy EnableColorSelection feature: due to a non-inclusive coordinate comparison, you were not allowed to color a single character; but I see no reason why that should be disallowed. Now you can make all your `X`s red if you like. "Soft" spots: * I was a bit surprised at some of the helpers I had to provide in textBuffer.cpp. Perhaps there are existing methods that I didn't find? * Localization? Because there are so many (40!) actions, I went to some trouble to try to provide nice command/arg descriptions. But I don't know how localization works… <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #9583 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed *(what would be the right place to add tests for this?)* * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [ ] Schema updated. *(is this needed?)* * [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Validation Steps Performed Just manual testing. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:35:30 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#29540