Skip to content

Commit cdc164c

Browse files
authored
Generate OnIdle event only if the editing buffer is empty (#2934)
1 parent 4e8c8a0 commit cdc164c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

PSReadLine/ReadLine.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,25 @@ internal static PSKeyInfo ReadKey()
218218
bool runPipelineForEventProcessing = false;
219219
foreach (var sub in eventSubscribers)
220220
{
221-
runPipelineForEventProcessing = true;
222221
if (sub.SourceIdentifier.Equals(PSEngineEvent.OnIdle, StringComparison.OrdinalIgnoreCase))
223222
{
224-
// There is an OnIdle event. We're idle because we timed out. Normally
225-
// PowerShell generates this event, but PowerShell assumes the engine is not
226-
// idle because it called PSConsoleHostReadLine which isn't returning.
227-
// So we generate the event instead.
223+
// If the buffer is not empty, let's not consider we are idle because the user is in the middle of typing something.
224+
if (_singleton._buffer.Length > 0)
225+
{
226+
continue;
227+
}
228+
229+
// There is an OnIdle event subscriber and we are idle because we timed out and the buffer is empty.
230+
// Normally PowerShell generates this event, but PowerShell assumes the engine is not idle because
231+
// it called PSConsoleHostReadLine which isn't returning. So we generate the event instead.
232+
runPipelineForEventProcessing = true;
228233
_singleton._engineIntrinsics.Events.GenerateEvent(PSEngineEvent.OnIdle, null, null, null);
229234

230235
// Break out so we don't genreate more than one 'OnIdle' event for a timeout.
231236
break;
232237
}
238+
239+
runPipelineForEventProcessing = true;
233240
}
234241

235242
// If there are any event subscribers, run a tiny useless PowerShell pipeline

0 commit comments

Comments
 (0)