Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement copy and paste for keyboard shortcuts #1072

Closed
wants to merge 4 commits into from
Closed

Implement copy and paste for keyboard shortcuts #1072

wants to merge 4 commits into from

Conversation

d-bingham
Copy link
Contributor

@d-bingham d-bingham commented May 30, 2019

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

  • Closes Copy & Paste Keybindings #968
  • 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. Issue number where discussion took place: Copy & Paste Keybindings #968

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).

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather we break this into two PR's:

  • one for adding the copy and paste keybindings (which will probably require minimal changes, if any to get in)
  • another for the line endings conversion on paste.

The first is a much simpler change that I think we'd all easily get behind, with the second might involve a bit more discussion.

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label May 31, 2019
@d-bingham
Copy link
Contributor Author

Closing this to split into two PRs.

@d-bingham d-bingham closed this Jun 1, 2019
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jun 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy & Paste Keybindings
3 participants