[PR #1072] [CLOSED] Implement copy and paste for keyboard shortcuts #24468

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/1072
Author: @d-bingham
Created: 5/30/2019
Status: Closed

Base: masterHead: master


📝 Commits (4)

  • 0b3d1b7 Attach copy and paste functionality to their keyboard shortcuts and add the option to strip line feeds from pasted text.
  • 23dd6d9 Fixing tabs on .idl files
  • 970764f Added description of TermControl::PasteTextFromClipboard
  • 411bb3e Changing line-ending paste option to specifically target CRLF pairs and renamed it appropriately.

📊 Changes

10 files changed (+98 additions, -7 deletions)

View changed files

📝 src/cascadia/TerminalApp/App.cpp (+15 -0)
📝 src/cascadia/TerminalApp/App.h (+1 -0)
📝 src/cascadia/TerminalApp/Profile.cpp (+18 -0)
📝 src/cascadia/TerminalApp/Profile.h (+1 -0)
📝 src/cascadia/TerminalControl/TermControl.cpp (+45 -7)
📝 src/cascadia/TerminalControl/TermControl.h (+2 -0)
📝 src/cascadia/TerminalControl/TermControl.idl (+1 -0)
📝 src/cascadia/TerminalSettings/IControlSettings.idl (+1 -0)
📝 src/cascadia/TerminalSettings/TerminalSettings.cpp (+11 -0)
📝 src/cascadia/TerminalSettings/terminalsettings.h (+3 -0)

📄 Description

Summary of the Pull Request

Attaches copy/paste functionality to their keyboard shortcuts and adds an option to improve interaction between "Windows-space" clipboards and "Linux-space" Terminals.

References

#968

PR Checklist

Detailed Description of the Pull Request / Additional comments

This connects the (mostly) pre-existing copy/paste mechanics to the keyboard shortcut mechanics, and adds a new option which makes multi-line pasting in WSL actually usable.

The new option, convertPasteLineEndings does what it says -- replacing Windows-space CRLF pairs with Unix-space LFs in text pasted to the console. This option applies to both the keyboard-shortcut paste and the right-click paste. Without this most multiline text pasted into Terminal will be "double-spaced" due to the Windows-style CRLF pairs. Furthermore, any multiline text copied from Terminal (in trim whitespace mode) generates CRLF pairs, which guarantees double-spacing when copying from a WSL Terminal session.

Changes:

  • Added TermControl::PasteTextFromClipboard which does what it says on the tin. Refactored the paste code from the right-click handling in TermControl here.
  • Added App::_PasteText, functioning in parallel to the pre-existing App::_CopyText
  • Added TermControl::_SendPastedTextToConnection which adds a pre-processing layer on top of _SendInputToConnection to allow line-ending conversion
  • Added connections from keybindings to copy/paste functionality in App::_HookupKeyBindings
  • Various code in Profile/TerminalSettings to support the new option "convertPasteLineEndings" (optional, defaults to false)

Other notes:

  • This PR interprets the keybinding "copy" as a copy trimming trailing whitespace (the operation performed by a right-click with a selection active). It may be appropriate to add a keybinding for a whitespace-preserving copy (which is now done as a shift-right-click with a selection active).
  • Windows -> Unix line-ending conversion is pretty much unavoidable for Terminal to interact happily with WSL. TextBuffer::GetTextForClipboard inserts CRLF pairs into copied text, and while this could be changed to (optionally) generate LFs instead of CRLFs, this doesn't seem to be sufficient since (e.g.) Notepad also happily generates CRLF pairs.
  • The architecture for the copy/paste functionality is... odd, at least to my mind. This PR follows the existing mechanisms as closely as possible (the additional paste functions closely mirror the existing copy functions), but stuff like App::_CreateNewTabFromSettings filling out the event handlers as opposed to TermControl probably deserves an eyeball, as the only knowledge not available to TermControl during this process is which DependencyObject the Dispatcher for the copy/paste operations should come from (and I'm not sure this particularly matters).

🔄 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/1072 **Author:** [@d-bingham](https://github.com/d-bingham) **Created:** 5/30/2019 **Status:** ❌ Closed **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (4) - [`0b3d1b7`](https://github.com/microsoft/terminal/commit/0b3d1b7eeac9e0c00fecce4a86cb11b82cad8814) Attach copy and paste functionality to their keyboard shortcuts and add the option to strip line feeds from pasted text. - [`23dd6d9`](https://github.com/microsoft/terminal/commit/23dd6d934ecfae3a206ae1c70ecc3907e48bbb43) Fixing tabs on .idl files - [`970764f`](https://github.com/microsoft/terminal/commit/970764f93b90a9882490e3caa9c9f764e85286f2) Added description of TermControl::PasteTextFromClipboard - [`411bb3e`](https://github.com/microsoft/terminal/commit/411bb3efb82f0276c947789ad10df91af4276342) Changing line-ending paste option to specifically target CRLF pairs and renamed it appropriately. ### 📊 Changes **10 files changed** (+98 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalApp/App.cpp` (+15 -0) 📝 `src/cascadia/TerminalApp/App.h` (+1 -0) 📝 `src/cascadia/TerminalApp/Profile.cpp` (+18 -0) 📝 `src/cascadia/TerminalApp/Profile.h` (+1 -0) 📝 `src/cascadia/TerminalControl/TermControl.cpp` (+45 -7) 📝 `src/cascadia/TerminalControl/TermControl.h` (+2 -0) 📝 `src/cascadia/TerminalControl/TermControl.idl` (+1 -0) 📝 `src/cascadia/TerminalSettings/IControlSettings.idl` (+1 -0) 📝 `src/cascadia/TerminalSettings/TerminalSettings.cpp` (+11 -0) 📝 `src/cascadia/TerminalSettings/terminalsettings.h` (+3 -0) </details> ### 📄 Description <!-- 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 Attaches copy/paste functionality to their keyboard shortcuts and adds an option to improve interaction between "Windows-space" clipboards and "Linux-space" Terminals. <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References #968 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #968 * [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 * [ ] 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: #968 <!-- 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 This connects the (mostly) pre-existing copy/paste mechanics to the keyboard shortcut mechanics, and adds a new option which makes multi-line pasting in WSL actually _usable_. The new option, *convertPasteLineEndings* does what it says -- replacing Windows-space CRLF pairs with Unix-space LFs in text pasted to the console. This option applies to both the keyboard-shortcut paste and the right-click paste. Without this most multiline text pasted into Terminal will be "double-spaced" due to the Windows-style CRLF pairs. Furthermore, any multiline text copied from Terminal (in trim whitespace mode) generates CRLF pairs, which guarantees double-spacing when copying from a WSL Terminal session. Changes: - Added TermControl::PasteTextFromClipboard which does what it says on the tin. Refactored the paste code from the right-click handling in TermControl here. - Added App::_PasteText, functioning in parallel to the pre-existing App::_CopyText - Added TermControl::_SendPastedTextToConnection which adds a pre-processing layer on top of _SendInputToConnection to allow line-ending conversion - Added connections from keybindings to copy/paste functionality in App::_HookupKeyBindings - Various code in Profile/TerminalSettings to support the new option "convertPasteLineEndings" (optional, defaults to false) Other notes: - This PR interprets the keybinding "copy" as a copy trimming trailing whitespace (the operation performed by a right-click with a selection active). It may be appropriate to add a keybinding for a whitespace-preserving copy (which is now done as a shift-right-click with a selection active). - Windows -> Unix line-ending conversion is pretty much unavoidable for Terminal to interact happily with WSL. TextBuffer::GetTextForClipboard inserts CRLF pairs into copied text, and while this could be changed to (optionally) generate LFs instead of CRLFs, this doesn't seem to be sufficient since (e.g.) Notepad also happily generates CRLF pairs. - The architecture for the copy/paste functionality is... odd, at least to my mind. This PR follows the existing mechanisms as closely as possible (the additional paste functions closely mirror the existing copy functions), but stuff like App::_CreateNewTabFromSettings filling out the event handlers as opposed to TermControl probably deserves an eyeball, as the only knowledge not available to TermControl during this process is which DependencyObject the Dispatcher for the copy/paste operations should come from (and I'm not sure this particularly matters). --- <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:03:29 +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#24468