[PR #1224] Add support for HTML copy #24545

Closed
opened 2026-01-31 09:03:55 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/1224

State: closed
Merged: Yes


Summary of the Pull Request

HTML data is now copied to the clipboard. I tried reusing the old clipboard method so I had to move some stuff around. The design is pretty straightforward. Instead of sending just text data up on a CopyToClipboard event, send the HTML data up too in the same winrt object.

Here's some specifics:

  • Clipboard::GenHTML() Changes:
    • moved from Clipboard to TextBuffer
    • added iFontHeightPoints and fontFaceName so that I don't depend on the ServiceLocator
  • TermControl: have CopyToClipboardEventArgs have space for both data types
  • TerminalApp: just extract the data from the event and put it into the clipboard

References

#1146 (HTML portion)

PR Checklist

  • Closes half of install problem in version1809 (#1146)
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be updated
  • 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.

Detailed Description of the Pull Request / Additional comments

I do have a few things I'm not sure of:

  • As of now, HTML copy is always enabled. I can easily add make it optional but idk what the design should look like (i.e.: new keybinding copies only HTML?)
  • I don't think we can/should add tests to this because (1) it resuses old code and (2) we definitely don't want to actually copy stuff to the clipboard during a test. The only thing to test would be what GenHTML does but that was already here.
  • Not sure if the iFontHeightPointsis right (or even described properly for that matter) in GenHTML().
    • for Clipboard we do int const iFontHeightPoints = fontData.GetUnscaledSize().Y * 72 / ServiceLocator::LocateGlobals().dpi;
    • for TermControl I did fontData.GetUnscaledSize().Y
    • I don't really know how to verify if this is correct. But I also don't know if we actually even need the DPI here. Thoughts?

Validation Steps Performed

Copy selections and paste to MSWord (regular text vs formatted text)

**Original Pull Request:** https://github.com/microsoft/terminal/pull/1224 **State:** closed **Merged:** Yes --- <!-- 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 HTML data is now copied to the clipboard. I tried reusing the old clipboard method so I had to move some stuff around. The design is pretty straightforward. Instead of sending just text data up on a `CopyToClipboard` event, send the HTML data up too in the same winrt object. Here's some specifics: - `Clipboard::GenHTML()` Changes: - moved from `Clipboard` to `TextBuffer` - added `iFontHeightPoints` and `fontFaceName` so that I don't depend on the `ServiceLocator` - `TermControl`: have `CopyToClipboardEventArgs` have space for both data types - `TerminalApp`: just extract the data from the event and put it into the clipboard <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References #1146 (HTML portion) <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes half of #1146 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Requires documentation to be updated * [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. <!-- 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 I do have a few things I'm not sure of: - As of now, HTML copy is always enabled. I can easily add make it optional but idk what the design should look like (i.e.: new keybinding copies only HTML?) - I don't think we can/should add tests to this because (1) it resuses old code and (2) we definitely don't want to actually copy stuff to the clipboard during a test. The only thing to test would be what `GenHTML` does but that was already here. - Not sure if the `iFontHeightPoints`is right (or even described properly for that matter) in `GenHTML()`. - for `Clipboard` we do `int const iFontHeightPoints = fontData.GetUnscaledSize().Y * 72 / ServiceLocator::LocateGlobals().dpi;` - for `TermControl` I did `fontData.GetUnscaledSize().Y` - I don't really know how to verify if this is correct. But I also don't know if we actually even need the DPI here. Thoughts? ## Validation Steps Performed Copy selections and paste to MSWord (regular text vs formatted text)
claunia added the pull-request label 2026-01-31 09:03:55 +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#24545