Skip to content

Commit f4ee589

Browse files
committed
Right click w/ multiple lines pasted as a one line
This problem only happened in ValidateAndAcceptLine It also only happened if validation failed for any reason. The fix is to insert a newline even if validation failed if we still have pending input. If there is no pending input, we don't want to insert the newline, as this is the common case and people will not want to delete the blank line from the inserted newline.
1 parent 9c153bd commit f4ee589

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

PSReadLine/BasicEditing.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ private bool AcceptLineImpl(bool validate)
238238
_emphasisStart = -1;
239239
_emphasisLength = 0;
240240

241+
var insertionPoint = _current;
241242
// Make sure cursor is at the end before writing the line
242243
_current = _buffer.Length;
243244

@@ -254,6 +255,17 @@ private bool AcceptLineImpl(bool validate)
254255
var errorMessage = Validate(_ast);
255256
if (!string.IsNullOrWhiteSpace(errorMessage))
256257
{
258+
// If there are more keys, assume the user pasted with a right click and
259+
// we should insert a newline even though validation failed.
260+
if (_queuedKeys.Count > 0)
261+
{
262+
// Validation may have moved the cursor. Because there are queued
263+
// keys, we need to move the cursor back to the correct place, and
264+
// ignore where validation put the cursor because the queued keys
265+
// will be inserted in the wrong place.
266+
SetCursorPosition(insertionPoint);
267+
Insert('\n');
268+
}
257269
_statusLinePrompt = "";
258270
_statusBuffer.Append(errorMessage);
259271
_statusIsErrorMessage = true;

0 commit comments

Comments
 (0)