Allow config so that a right-click paste emits a ctrl+v (or other user defined key sequence) instead #15438

Open
opened 2026-01-31 04:38:40 +00:00 by claunia · 2 comments
Owner

Originally created by @SteveL-MSFT on GitHub (Oct 4, 2021).

Description of the new feature/enhancement

Per https://github.com/PowerShell/PSReadLine/issues/579 PSReadLine (which handles the interactive experience for PowerShell) cannot tell that the text is typed or pasted and can only treat it as typed. So newlines gets the input executed which can fail if the content is a multi-line script, for example:

if ($true -eq $false)
{
  'true'
}
else
{
  'false'
}

In this case, PowerShell will accept the individual lines for the if clause, but since else is optional, will execute the if part and then treats else as a command which fails. However, PSReadLine can handle pasting from the clipboard as it knows the entire content of the clipboard rather than seeing it character by character.

So instead of having Ctrl+v or Ctrl+Shift+v bound to terminal paste, let the shell handle it, but have the terminal emit a ctrl+v (or whatever user binding has been defined) on right-click of the mouse.

Originally created by @SteveL-MSFT on GitHub (Oct 4, 2021). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement Per https://github.com/PowerShell/PSReadLine/issues/579 PSReadLine (which handles the interactive experience for PowerShell) cannot tell that the text is typed or pasted and can only treat it as typed. So newlines gets the input executed which can fail if the content is a multi-line script, for example: ```powershell if ($true -eq $false) { 'true' } else { 'false' } ``` In this case, PowerShell will accept the individual lines for the `if` clause, but since `else` is optional, will execute the `if` part and then treats `else` as a command which fails. However, PSReadLine can handle pasting from the clipboard as it knows the entire content of the clipboard rather than seeing it character by character. So instead of having `Ctrl+v` or `Ctrl+Shift+v` bound to terminal paste, let the shell handle it, but have the terminal emit a `ctrl+v` (or whatever user binding has been defined) on right-click of the mouse.
claunia added the Area-SettingsIssue-TaskProduct-TerminalArea-TerminalControl labels 2026-01-31 04:38:41 +00:00
Author
Owner

@j4james commented on GitHub (Oct 5, 2021):

Wouldn't bracketed paste mode help with this? Because that would improve the experience across all terminals (at least those that support the mode, but that probably includes most modern terminals).

Edit: Just reading the PSReadLine issue now, I see you were already considering bracketed paste, but it's apparently non-trivial to support. I'd still argue that's the right approach to take, because this just seems like a hack.

@j4james commented on GitHub (Oct 5, 2021): Wouldn't [bracketed paste mode](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode) help with this? Because that would improve the experience across all terminals (at least those that support the mode, but that probably includes most modern terminals). Edit: Just reading the PSReadLine issue now, I see you were already considering bracketed paste, but it's apparently non-trivial to support. I'd still argue that's the right approach to take, because this just seems like a hack.
Author
Owner

@zadjii-msft commented on GitHub (Oct 5, 2021):

Okay so this sounds like a part of #1553 to me, allowing a user to bind right mouse to a sendInput("^V") action.

Actually now after reading @j4james comment, yea I think bracketed paste would be more general purpose here. That would work regardless of how the text was pasted. Think also of the future world where there's an (optional) right-click context menu in the Terminal, that lets the user paste from that menu. That would also have to be rebound, should the user want to do that.

I'll leave this open, but this really feels like a dup of https://github.com/PowerShell/PSReadLine/issues/1471#issuecomment-779403823 to me.

@zadjii-msft commented on GitHub (Oct 5, 2021): Okay so this sounds like a part of #1553 to me, allowing a user to bind right mouse to a `sendInput("^V")` action. Actually now after reading @j4james comment, yea I think bracketed paste would be more general purpose here. That would work regardless of how the text was pasted. Think also of the future world where there's an (optional) right-click context menu in the Terminal, that lets the user paste from that menu. That would also have to be rebound, should the user want to do that. I'll leave this open, but this really feels like a dup of https://github.com/PowerShell/PSReadLine/issues/1471#issuecomment-779403823 to me.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#15438