Skip to content

Commit 454453e

Browse files
committed
Fix bug where console paste mixes up keys
Console paste was broken by the fix to exit w/o delay because I needed to reconsider the logic of ReadKey instead of just refactoring the code onto another thread.
1 parent ad4f871 commit 454453e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

PSReadLine/ReadLine.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,12 @@ private void ReadKeyThreadProc()
209209
}
210210
}
211211

212-
var key = _queuedKeys.Count > 0
213-
? _queuedKeys.Dequeue()
214-
: Console.ReadKey(true);
215-
if (_captureKeys)
212+
if (_queuedKeys.Count == 0)
216213
{
217-
_savedKeys.Enqueue(key);
214+
var key = Console.ReadKey(true);
215+
_queuedKeys.Enqueue(key);
218216
}
219217

220-
_queuedKeys.Enqueue(key);
221-
222218
// One or more keys were read - let ReadKey know we're done.
223219
_keyReadWaitHandle.Set();
224220
}
@@ -250,7 +246,12 @@ private static ConsoleKeyInfo ReadKey()
250246
// where we can return from ReadLine.
251247
throw new OperationCanceledException();
252248
}
253-
return _singleton._queuedKeys.Dequeue();
249+
var key = _singleton._queuedKeys.Dequeue();
250+
if (_singleton._captureKeys)
251+
{
252+
_singleton._savedKeys.Enqueue(key);
253+
}
254+
return key;
254255
}
255256

256257
private bool BreakHandler(ConsoleBreakSignal signal)

0 commit comments

Comments
 (0)