Skip to content

bug: TextField native undo (ctrl + z) causes the cursor to jump to the end of the text. #5759

@StianHanssen

Description

@StianHanssen

Duplicate Check

Describe the bug

I wanted to implement undo/redo on a TextField, but I found out that the field natively supports it with ctrl + z and ctrl + shift + z. However, when I do an undo, the cursor tends to jumps to the end of the text, and I can't find a way to prevent it.

Code sample

Code
ft.TextField(
    label="Test",
    multiline=True,
    min_lines=5,
    hint_text="Just trying some text",
    width=700,
    border_color=ft.Colors.GREY_300,
    focused_border_color=ft.Colors.GREY_600,
    expand=True,
)

To reproduce

  1. Start up an application with a simple multiple text field, as I provided in the code example.
  2. Paste in a few paragraphs of text.
  3. Make some edits.
  4. Perform ctrl + z
  5. At least on Ubuntu, this causes the cursor to jump to the end of the text.

Expected behavior

I expect the cursor to stay at the current location when ctrl + z is pressed.

Screenshots / Videos

Captures
2025-10-29.10-59-05.mp4

Operating System

Linux

Operating system details

Ubuntu 24.04.3 LTS

Flet version

0.28.3

Regression

I'm not sure / I don't know

Suggestions

I am not at all a dart expert, so this could be way off, but I thought it could have something to do with: packages/flet/lib/src/controls/textfield.dart, where we set selection: TextSelection.collapsed(offset: value.length).

Logs

Logs

I just start the python code:

python main.py

Additional details

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions