Right-Click Paste in PowerShell with PSReadLine results in CTRL-ENTER, can cause PSReadLine fault in SetCursorPosition #4362

Open
opened 2026-01-30 23:45:12 +00:00 by claunia · 0 comments
Owner

Originally created by @msftrncs on GitHub (Oct 9, 2019).

Environment

Windows build number: Windows 10 Insiders 18995 (until the next update)
Windows Terminal version: 0.5.2762.0

Any other software?
PowerShell: any version with PSReadLine
PSReadLine, 2.0.0 beta 2 through 5

Steps to reproduce

See also: https://github.com/PowerShell/PSReadLine/issues/1081

  1. Copy some script with multiple lines from somewhere, an editor like VS Code for instance, or even from the code section of this issue.
  2. Use PowerShell with PSReadLine installed
  3. Right-click paste in to the Windows Terminal session of PowerShell.

The issue will be amplified if the current cursor/prompt is already at the bottom of the window, as is shown below.

Expected behavior

A paste to occur just as in Conhost.

Actual behavior

Without PSReadLine loaded, this behavior will not be noticed, but this is just because PSReadLine uses CTRL-ENTER to insert lines past the cursor's position.

CTRL-ENTER is getting pasted along with regular ENTER, causing PSReadLine to attempt to advance past the end of the buffer, causing an exception in SetCursorPosition, in addition to blank unnecessary lines.

image

What I pasted was:

filter val_2_base33 ([int]$digits = 1) {
    # convert value to base 33 (VIN) string representation
    [int]$value = $_
    [string]$result = ''
    [int]$digs = 0
    while (++$digs -le $digits -or $value -gt 0) {
        $result = '0123456789ABCDEFGHJKLMNPRSTUVWXYZ'[$value % 33] + $result
        $value = [math]::Truncate($value / 33)
    }
    $result
}

Problem doesn't seem to happen if using CTRL-V.

I think the issue is that CTRL-ENTER aka CTRL-J aka LineFeed is contained in the clipboard copy of the data, and its not being filtered out when Right-Click paste. Is there a reason for that, or is this an accident?

Originally created by @msftrncs on GitHub (Oct 9, 2019). # Environment ```none Windows build number: Windows 10 Insiders 18995 (until the next update) Windows Terminal version: 0.5.2762.0 Any other software? PowerShell: any version with PSReadLine PSReadLine, 2.0.0 beta 2 through 5 ``` # Steps to reproduce See also: https://github.com/PowerShell/PSReadLine/issues/1081 1. Copy some script with multiple lines from somewhere, an editor like VS Code for instance, or even from the code section of this issue. 1. Use PowerShell with PSReadLine installed 1. Right-click paste in to the Windows Terminal session of PowerShell. The issue will be amplified if the current cursor/prompt is already at the bottom of the window, as is shown below. # Expected behavior A paste to occur just as in Conhost. # Actual behavior Without PSReadLine loaded, this behavior will not be noticed, but this is just because PSReadLine uses CTRL-ENTER to insert lines past the cursor's position. CTRL-ENTER is getting pasted along with regular ENTER, causing PSReadLine to attempt to advance past the end of the buffer, causing an exception in SetCursorPosition, in addition to blank unnecessary lines. ![image](https://user-images.githubusercontent.com/26179051/66089060-4550bf00-e543-11e9-8ef7-a28735b80d0e.png) What I pasted was: ```PowerShell filter val_2_base33 ([int]$digits = 1) { # convert value to base 33 (VIN) string representation [int]$value = $_ [string]$result = '' [int]$digs = 0 while (++$digs -le $digits -or $value -gt 0) { $result = '0123456789ABCDEFGHJKLMNPRSTUVWXYZ'[$value % 33] + $result $value = [math]::Truncate($value / 33) } $result } ``` Problem doesn't seem to happen if using CTRL-V. I think the issue is that CTRL-ENTER aka CTRL-J aka LineFeed is contained in the clipboard copy of the data, and its not being filtered out when Right-Click paste. Is there a reason for that, or is this an accident?
claunia added the Resolution-Duplicate label 2026-01-30 23:45:12 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#4362