Skip to content

Bug: Incorrect Caret Position After Undo in CodeArea #1293

@Symeon94

Description

@Symeon94

I've encountered an unexpected bug in the undo behavior of the CodeArea. It seems that when pressing Enter after selecting text, and then performing an undo (CTRL+Z), the caret is not restored to its original position. Instead, it ends up one character before the end of the original selection.

Steps to Reproduce

  1. In a CodeArea, type any text — for example: Something,
  2. Select a portion of the text — e.g., select "eth" in Som[eth]ing,
  3. Press Enter — the result will be Som\ning with the caret positioned at the start of the second line,
  4. Press CTRL+Z to undo — the text reverts to Something, but the caret is now placed after the letter 't' instead of its original position and there is no selection.

Expected Behavior

The undo operation should restore both:

  • The original selection range
  • The caret position exactly as it was before pressing Enter

Additional Notes

  • Selection direction matters: selecting from 'e' to 'h' vs. 'h' to 'e' should not affect the final caret position after undo.
  • The caret should consistently return to its pre-Enter location regardless of selection direction.

Update: I suspect the issue is in the UndoManager, so it might be a bug to be reported there instead, I will look for the root cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions