prompt-toolkit / prompt-toolkit/python-prompt-toolkit

You can input multiline text in `TextArea` when `multiline=False`

Open
#1,894 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

The app:

from prompt_toolkit import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.layout.containers import Window, HSplit
from prompt_toolkit.layout.controls import BufferControl
from prompt_toolkit.layout.layout import Layout

from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.widgets import TextArea

kb = KeyBindings()

@kb.add('c-q')
def exit_(event):
  event.app.exit()

buffer1 = Buffer()  # Editable buffer.

root_container = HSplit([
  TextArea(
    prompt='Type something: ',
    multiline=False,
    wrap_lines=False,
    accept_handler=lambda buff: buffer1.insert_text(f"accept_handler called: {buff.text}\n"),
  ),
  Window(height=1, char='-'),
  Window(content=BufferControl(buffer=buffer1)),
])

layout = Layout(root_container)

app = Application(key_bindings=kb, layout=layout, full_screen=True)
app.run()

When multiline=False, pressing enter should trigger accept_handler.

However, when pasting multi-line text to the console, TextArea draws a new line then scroll down. In this case, accept_handler won't be triggered.

Another way to trigger this bug is to type very fast when the computer is slow. I guess it works similarly as copy-pasting.

Windows 10
prompt_toolkit 3.0.47
cmd.exe + Windows Terminal

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided TextArea example with multiline=False, especially the paste or rapid-input path on Windows. Trace TextArea and its input handling to determine why a newline is drawn instead of invoking accept_handler; done means multiline input consistently triggers the handler without inserting a new line.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.