Skip to content

You can input multiline text in TextArea when multiline=False #1894

@eight04

Description

@eight04

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions