Maniphest T80611

Text Editor: Missing undo for text operators when in edit mode
Closed, Duplicate

Assigned To
None
Authored By
Kai Jægersen (kaio)
Sep 9 2020, 12:16 AM
Tags
  • BF Blender
  • Python API
Subscribers
Campbell Barton (campbellbarton)
Germano Cavalcante (mano-wii)
Kai Jægersen (kaio)

Description

System Information
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 441.87

Blender Version
Broken: version: 2.91.0 Alpha, branch: master, commit date: 2020-09-07 08:12, hash: rBb351607996e4
Worked: Some time before binary diffing was implemented maybe?

Short description of error

Note: This is about text editor operators, nothing to do with Text objects in the viewport.

Custom text operators that modify the text (text.body, text.write(), etc.) are missing undo steps IFF an object is in edit mode.
When an object is in object mode, however, the undo works as expected.

Text operators implemented in C work fine. Assuming the solution is letting custom operators push or tag undo like internal ones.

Exact steps for others to reproduce the error

  1. Load the example blend. The cube will be in edit mode.
  2. Run script. A new button "Modify Body" is placed in the header of Text Editor.
  3. Click the button a few times.
  4. Try to undo (doesn't work)
  5. Toggle to Object mode and do steps 3 and 4 again (undo works)

Event Timeline

Kai Jægersen (kaio) created this task.Sep 9 2020, 12:16 AM
Germano Cavalcante (mano-wii) added a project: Python API.EditedSep 11 2020, 7:51 PM
Germano Cavalcante (mano-wii) added a subscriber: Germano Cavalcante (mano-wii).

The undo system is confusing.
There are many reports on global undo that seem to be related.
The text editor has its own undo context, but apparently it doesn't work on python operators.
Maybe this system needs to be rewritten (there are already tasks designed to do this T68068, T71735)

I'm not sure if this is something that can be fixed in a short time.

Kai Jægersen (kaio) added a comment.Sep 12 2020, 1:25 AM

Thanks, I've been looking for those tasks. I wasn't sure if there was a specific report for this.

A workaround to getting undo to work in edit mode for custom operators is to register a Macro which defines two operators:

  1. An internal operator eg. TEXT_OT_insert
  2. My custom python operator

The result is that the macro is able to piggyback the undo pushed by TEXT_OT_insert.
While this works it requires a macro operator, and the code just becomes confusing for others to read.

Philipp Oeser (lichtwerk) changed the task status from Needs Triage to Confirmed.Sep 14 2020, 6:59 PM
Campbell Barton (campbellbarton) added a subscriber: Campbell Barton (campbellbarton).Sep 17 2020, 2:28 AM

We need to expose undo for text operators written in Python, currently in C this is done explicitly, it would be nice to avoid begin/end calls to the undo system although I don't see good way around this (that doesn't further complicate undo).

Added design task which links to this task.

Campbell Barton (campbellbarton) closed this task as a duplicate of T80864: Undo fails with Python text editor operators while in edit-mode.Sep 17 2020, 2:29 AM