Skip to content

PyREPL: ESC key in isearch mode has ambiguous prefix delay #154730

Description

@tanloong

Bug report

Bug description:

This issue was noted from #145398. A bare Esc press in isearch mode (Ctrl-R) does not exit search. Instead, the first Esc appears to do nothing, only after pressing Esc a second time does isearch end.

To reproduce:

  1. Press Ctrl-R in PyREPL to enter isearch.
  2. Press Esc once to exit isearch.
  • Expected: isearch ends immediately.
  • Actual: nothing happens. Press Esc again, isearch ends.

This is because BaseEventQueue.push() treats \x1b (ESC) as a prefix of longer escape sequences (arrows, function keys, etc.). When a single Esc is received, the event queue holds it and waits for the next byte to decide whether it’s a standalone Esc or the start of a longer sequence. If no further byte arrives, the Esc event is never delivered, and isearch remains active.

Apart from isearch mode, this behavior affects normal mode as well, where Esc also has a delay before it is recognized.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions